Erase (statement)


Erase array1 [,array2]...


Erases the elements of the specified arrays.


For dynamic arrays, the elements are erased, and the array is redimensioned to have no dimensions (and therefore no elements). For fixed arrays, only the elements are erased; the array dimensions are not changed.


After a dynamic array is erased, the array will contain no elements and no dimensions. Thus, before the array can be used by your program, the dimensions must be reestablished using the Redim statement.

Up to 32 parameters can be specified with the Erase statement.


The meaning of erasing an array element depends on the type of the element being erased:


Element Type

What Erase Does to That Element



Sets the element to 0.



Sets the element to FALSE.



Sets the element to 0.



Sets the element to 0.0.



Sets the element to December 30, 1899.



Sets the element to 0.0.


String (variable-length)

Frees the string, then sets the element to a zero-length string.


String (fixed-length)

Sets every character of each element to zero (Chr$(0)).



Decrements the reference count and sets the element to Nothing.



Sets the element to Empty.


User-defined type

Sets each structure element as a separate variable.


This example fills an array with a list of available disk drives, displays the list, erases the array and then redisplays the list.

Sub Main()
  Dim a$(10)  'Declare an array.
  DiskDrives a  'Fill element 1 with a list of available disk drives.
  r = SelectBox("Array Before Erase",,a)
  Erase a$    'Erase all elements in the array.
  r = SelectBox("Array After Erase",,a)
End Sub

See Also

Redim (statement); Arrays (topic).

More information