Solved

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

Posted on 1998-12-16
9
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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