View Single Post
  #5   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?

That clarifies things a lot. For some reason, most of the examples I found
use the redim approach. I see the benefit of using redim to change the size
of the array, but it is not applicable in my case.

Thank You,
Joe Dunfee

"Bob Phillips" wrote:

Seems superfluous here to me, could just as easily do

Dim intArray(1 To 5, 1 To 5) As Integer


Another reason for using ReDim is when you pass the array size to a
function, but again not applicable here.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Joe Dunfee" wrote in message
...
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