Solved

redim vs. erase what is the difference

Posted on 2004-04-26
6
1,063 Views
Last Modified: 2006-11-17
redim vs. erase what is the difference?
I’m having a hard time understanding what the difference between using erase or redim to clear out an array. Can some one fill me in on the pros and Con’s of it?

Thanks
0
Comment
Question by:cdb424ttm
  • 3
  • 2
6 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 10919754
redim can't be used with static arrays.

erase will completely delete a variable arrays and will only reset values of static arrays.
0
 
LVL 33

Expert Comment

by:hongjun
ID: 10919765
ya redim will remove memory (without the preserve)
erase will also do
0
 
LVL 33

Expert Comment

by:hongjun
ID: 10919786
i am not sure what will be the difference in terms of "freeing memory" speed for hugh arrays.
if i am not wrong, i guess redim is faster.
perhaps emoreau can comment on this.
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.

 
LVL 33

Expert Comment

by:hongjun
ID: 10919831
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 10919898
Redim changes the size of an array.  So, for example, I can redim an array and change the size while simultaneously disposing of its contents (if I don't use Redim Preserve).  Erase simply disposes of the contents of the array.  If the array happens to be dynamic, then it also disposes of the array elements themselves, not just their contents.  In contrast, if I use Redim I cannot reduce the array to fewer than one element.  Erase also releases the memory associated with a dynamic array.

dim myArray()          'Create a dynamic array
redim myArray(9)     'Resize the array to 10 elements with the lowest being element 0
redim myArray(0)     'Knocks the array down to one element
redim myArray(9)     'Back to 10 elements
erase myArray          'Array now has no elements

0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 10920056
>>if i am not wrong, i guess redim is faster.
>>perhaps emoreau can comment on this.

I have no idea on this.
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

Title # Comments Views Activity
Use Multiple Forms 4 48
Excel object stays open 19 70
Notepad++ how to remove delimiter : from beggning of the line? 3 93
vb6 connector to mongodb 2 48
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
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…

914 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

20 Experts available now in Live!

Get 1:1 Help Now