View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default redim multiarray

The rule with multi dim arrays is that you can only redim the last element in
the array. Once created the first element is permanent. So code like this
will work...

Sub test()
Dim ary() As String

ReDim ary(10, 10)
ary(1, 1) = "Tada"
ReDim Preserve ary(10, 11)
End Sub

But code like this will not work
Sub test()
Dim ary() As String

ReDim ary(10, 10)
ary(1, 1) = "Tada"
ReDim Preserve ary(11, 11)
End Sub

It has to do with the way memory is stored. A multi dim array, like any
array, is stored as a big long memory string. Adding to the final element
adds another entire block to the end of the memory. Adding to the first
element(s) would require adding more memory to each of the already existing
block which it just will not do.
--
HTH...

Jim Thomlinson


"ranswert" wrote:

How do I declare a multidimensional array where the first dimension
upperbound is known, but the second dimension upperbound is not known ?
Also, how do I 'redim' that array when the second dimension upperbound is
known?
Thanks