• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

--------------- 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
0
dgb001
Asked:
dgb001
1 Solution
 
ChasDevlinCommented:
ReDim ArrayName(50) - this sets everything back to defaults i.e. zeroes or ""

ReDim Preserve(50) = this keeps your CURRENT values intact.


0
 
vmanoCommented:
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


0
 
dgb001Author Commented:
Ok guys, I'll try out your suggestions. Thanks for taking the time to add your comments.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
ChizlCommented:
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.

0
 
NickHCommented:
Don't forget also, you can only redim an array in one dimension.  The other dimension must stay constant.
0
 
dgb001Author Commented:
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

0
 
vmanoCommented:
dbg001,
can i post my comment as answer???

vmano
0
 
dgb001Author Commented:
Yes, sure vmano. Thanks for your help.
Dave

0
 
vmanoCommented:
thanks and here my comment as answer:
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.
 
vmano

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now