I have an array like this:
Dim aFirstArray() As Variant
How do I clear the entire array? What about a collection?
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.
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.
list. clear() is documented for clearing the ArrayList.
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
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!
It is as simple as :
Erase aFirstArray
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With