Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Why use redim when creating an array of arrays?

As I got more into using the code, I ran into problems. The master-array
elements must set equal to the sub-arrays only AFTER the values are entered
for the sub-arrays. It seems that once you create the array-within-an-array,
the values of the elements are set and cannot be changed. Here is my sample
code with comments;

'==================
Sub ABC()
Dim vArr1(1 To 10) As Variant
Dim vArr2(1 To 5) As Variant
Dim vMainArr(1 To 2) As Variant
Dim lCounter As Long
Dim s As String, i As Long, j As Long

' Populate the sub arrays:
For lCounter = 1 To 10
vArr1(lCounter) = lCounter
If lCounter < 6 Then _
vArr2(lCounter) = lCounter * 2
Next lCounter

' Assign the sub arrays to the main array:
' Note that this must be done after the sub arrays are populated with values
vMainArr(1) = vArr1
vMainArr(2) = vArr2

'change one of the elements as a test
vArr2(2) = 100 ' note that this change WON'T show in the vMainArr array

' Show the results
s = ""
For i = 1 To 2
For j = LBound(vMainArr(i), 1) To UBound(vMainArr(i), 1)
s = s & vMainArr(i)(j) & ","
Next j
s = s & vbNewLine
Next i
MsgBox s

End Sub

'==================

Joe Dunfee
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ReDim Array Brandt Excel Programming 3 October 9th 06 06:42 PM
ReDim Array Viktor Ygdorff Excel Programming 2 July 10th 06 04:04 PM
Creating a single vertical array from multiple column arrays Bryan Excel Worksheet Functions 2 December 10th 05 07:12 PM
ReDim Object array as parameter of Variant array Peter T Excel Programming 4 May 10th 05 02:11 PM
ReDim, Preserve and Multidimensional arrays Andy Westlake[_2_] Excel Programming 3 October 19th 04 07:04 PM


All times are GMT +1. The time now is 12:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"