View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Joe Dunfee Joe Dunfee is offline
external usenet poster
 
Posts: 10
Default Why use redim when creating an array of arrays?

Here is the code using redim I found in the "Collection vs. Array of Arrays"
thread.

'-------------------------------------
Sub TestCollectionAccess()
Dim col As VBA.Collection
Dim intArray() As Integer
Dim strarray() As String
Dim x As Long
Dim y As Long
Dim z As Variant
Dim zz As Variant

ReDim intArray(1 To 5, 1 To 5)
ReDim strarray(1 To 5, 1 To 5)

'Load the integer array
For x = 1 To 5
For y = 1 To 5
intArray(x, y) = x * y
Next
Next

'Get value
z = intArray(3, 4)

'Load the collection
Set col = New Collection
col.Add intArray
col.Add strarray

'Get value
zz = col(1)(3, 4)

MsgBox z & " and " & zz & " should be the same "
Set col = Nothing
End Sub
'-----------------------------


And here is another example [from
http://en.wikibooks.org/wiki/Program...lassic/Arrays]

The real power of arrays comes when defining arrays of arrays. What does
this mean? Declare an array:

'-------------------------------
Dim varray() As Variant

varray = Array()
ReDim varray(1) As Variant
varray(0) = Array(1,2,3)
varray(1) = Array(4,5,6)
What do we have here? Essentially two arrays inside another. They can be
reference like this:
Debug.Print varray(0)(2)
'-----------------------------

Joe Dunfee