Reinitializes the elements of fixed-size arrays and deallocates dynamic-array storage space.
Erase arraylist
The arraylist argument is one or more comma-delimited array variables to be erased.
It is important to know whether an array is fixed-size (ordinary) or dynamic because Erase behaves differently depending on the type of array. Erase recovers no memory for fixed-size arrays. Erase sets the elements of a fixed array as follows:
Type of array |
Effect of Erase on fixed-array elements |
Fixed numeric array |
Sets each element to zero. |
Fixed string array (variable length) |
Sets each element to zero-length (""). |
Fixed string array (fixed length) |
Sets each element to zero. |
Fixed Variant array |
Sets each element to Empty. |
Array of user-defined types |
Sets each element as if it were a separate variable. |
Array of objects |
Sets each element to the special value Nothing. |
Erase frees the memory used by dynamic arrays. Before your program can refer to the dynamic array again, it must redeclare the array variable’s dimensions using a ReDim statement.
Array Function, Dim Statement, Nothing, Private Statement, Public Statement, ReDim Statement, Static Statement.
This example uses the Erase statement to reinitialize the elements of fixed-size arrays and deallocate dynamic-array storage space.
' Declare array variables.NumArray(10) As Integer ' Integer array.StrVarArray(10) As String ' Variable-string array.StrFixArray(10) As String * 10 ' Fixed-string array.VarArray(10) As Variant ' Variant array.DynamicArray() As Integer ' Dynamic array.DynamicArray(10) ' Allocate storage space.NumArray ' Each element set to 0.StrVarArray ' Each element set to zero-length ' string ("").StrFixArray ' Each element set to 0.VarArray ' Each element set to Empty.DynamicArray ' Free memory used by array.