Solved

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

Posted on 1998-12-16
9
170 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

Technology Partners: 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!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 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