Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the entire array?

Tags:

arrays

excel

vba

I have an array like this:

Dim aFirstArray() As Variant

How do I clear the entire array? What about a collection?

like image 679
Alex Gordon Avatar asked Jun 10 '10 21:06

Alex Gordon


People also ask

How do I completely clear an array in C?

Use the memset Function to Clear Char Array in Ch> header file. memset takes three arguments - the first is the void pointer to the memory region, the second argument is the constant byte value, and the last one denotes the number of bytes to be filled at the given memory address.

How do you clear an array of values?

1) Assigning it to a new empty array This is the fastest way to empty an array: a = []; This code assigned the array a to a new empty array. It works perfectly if you do not have any references to the original array.

How do you clear a string array in Java?

list. clear() is documented for clearing the ArrayList.


3 Answers

You can either use the Erase or ReDim statements to clear the array. Examples of each are shown in the MSDN documentation. For example:

Dim threeDimArray(9, 9, 9), twoDimArray(9, 9) As Integer
Erase threeDimArray, twoDimArray
ReDim threeDimArray(4, 4, 9)

To remove a collection, you iterate over its items and use the Remove method:

For i = 1 to MyCollection.Count
  MyCollection.Remove 1 ' Remove first item
Next i
like image 109
Sarfraz Avatar answered Oct 03 '22 17:10

Sarfraz


For deleting a dynamic array in VBA use the instruction Erase.

Example:

Dim ArrayDin() As Integer    
ReDim ArrayDin(10)    'Dynamic allocation 
Erase ArrayDin        'Erasing the Array   

Hope this help!

like image 44
Andres Sommerhoff Avatar answered Oct 05 '22 17:10

Andres Sommerhoff


It is as simple as :

Erase aFirstArray
like image 7
Jaanus Avatar answered Oct 03 '22 17:10

Jaanus