dgb001
asked on
--------------- RE-DIMMING AN ARRAY ----------------
I have a two-dimensional public array, and want to be able to re-initailize it at given points in the program. I know that it's easy enough just to loop round and clear everything out, but can't help thinking there must be a proper way. I know that you can change the number of elements by using the REDIM statement, but I don't think that I can redim it to the same parameters, and thus clear it. I must admit I haven't tried this for a couple of months, so I'm talking about this from memory, but I know that I'm going to have to do the same thing again shortly. Any comments appreciated, but please don't log your comment as an answer unless you're 100% sure - this way other people get the chance to respond too. Thanks, Dave
to clear all the contents in an array use Erase statement:
Erase arraylist
The required arraylist argument is one or more comma-delimited array variables to be erased and then ReDim the Array
hope this helps
vmano
Erase arraylist
The required arraylist argument is one or more comma-delimited array variables to be erased and then ReDim the Array
hope this helps
vmano
ASKER
Ok guys, I'll try out your suggestions. Thanks for taking the time to add your comments.
ChasDevlin had it with a modification..
Dim ArrayName as Variant
>>ReDim ArrayName(50) as Variant - this sets everything back to defaults i.e. zeroes or ""
>>ReDim Preserve ArrayName(51) as Variant = this keeps your CURRENT values intact and adds a element.
Dim ArrayName as Variant
>>ReDim ArrayName(50) as Variant - this sets everything back to defaults i.e. zeroes or ""
>>ReDim Preserve ArrayName(51) as Variant = this keeps your CURRENT values intact and adds a element.
Don't forget also, you can only redim an array in one dimension. The other dimension must stay constant.
ASKER
Well, thanks for all the comments, but the one by vmano proved the most useful for my particular purposes. Using the erase statement does exactly what I want, and also you don't need to redim the array afterwards, it just clears the existing one. Many thanks.
Dave
Dave
dbg001,
can i post my comment as answer???
vmano
can i post my comment as answer???
vmano
ASKER
Yes, sure vmano. Thanks for your help.
Dave
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ReDim Preserve(50) = this keeps your CURRENT values intact.