Solved

--------------- RE-DIMMING AN ARRAY ----------------

Posted on 1998-12-16
9
164 Views
Last Modified: 2010-05-03
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
Comment
Question by:dgb001
9 Comments
 

Expert Comment

by:ChasDevlin
ID: 1450533
ReDim ArrayName(50) - this sets everything back to defaults i.e. zeroes or ""

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


0
 
LVL 3

Expert Comment

by:vmano
ID: 1450534
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
 
LVL 1

Author Comment

by:dgb001
ID: 1450535
Ok guys, I'll try out your suggestions. Thanks for taking the time to add your comments.

0
 
LVL 4

Expert Comment

by:Chizl
ID: 1450536
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:NickH
ID: 1450537
Don't forget also, you can only redim an array in one dimension.  The other dimension must stay constant.
0
 
LVL 1

Author Comment

by:dgb001
ID: 1450538
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
 
LVL 3

Expert Comment

by:vmano
ID: 1450539
dbg001,
can i post my comment as answer???

vmano
0
 
LVL 1

Author Comment

by:dgb001
ID: 1450540
Yes, sure vmano. Thanks for your help.
Dave

0
 
LVL 3

Accepted Solution

by:
vmano earned 50 total points
ID: 1450541
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now