Solved

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

Posted on 1998-12-16
9
163 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
Comment Utility
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
Comment Utility
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
Comment Utility
Ok guys, I'll try out your suggestions. Thanks for taking the time to add your comments.

0
 
LVL 4

Expert Comment

by:Chizl
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Expert Comment

by:NickH
Comment Utility
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
Comment Utility
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
Comment Utility
dbg001,
can i post my comment as answer???

vmano
0
 
LVL 1

Author Comment

by:dgb001
Comment Utility
Yes, sure vmano. Thanks for your help.
Dave

0
 
LVL 3

Accepted Solution

by:
vmano earned 50 total points
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

12 Experts available now in Live!

Get 1:1 Help Now