View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
LesHurley LesHurley is offline
external usenet poster
 
Posts: 61
Default array dimensioning

Ok chip, but if you ReDim it again the origional contents of the array are
set to zeros. I need to increase the size of the array to make room for more
data without losing the old data. for example, in a quick sort routine there
is no way to know how much space will be needed for each section of the data.
--
Thanks for your help


"Chip Pearson" wrote:

If you have a dynamic array (one in which the bounds are not specified in
the Dim statement), you can change the number of elements in the array with
the ReDim statement.

Dim Arr() As Long
ReDim Arr(0 To 9)

You can ReDim the array as often as you want. ReDim will cause the existing
contents of the array to be lost unless you use the Preserve modifier.

ReDim Preserve Arr(0 To 11)

You can change the number of dimensions of a dynamic array if you first
Erase the array.

Dim Arr() As Long
ReDim Arr(0 To 9)
' populate the array and do something
Erase Arr
ReDim Preserve Arr(0 To 9, 0 To 3)

None of this will work if the array is statically declared by specifying the
bounds in the Dim declaration.

Dim Arr(0 To 9) As Long
ReDim Arr(0 To 11) '<<<<< COMPILER ERROR


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





"LesHurley" wrote in message
...
In C++ one can expand or decrease the dimension an array. Can the same
thing
be done in VBA?
--
Thanks for your help