Name
Erase Statement
Syntax
Erase arraylist
-
arraylist
Use: Required
Datatype: Variant array
A list of array variables to clear.
Description
Resets the elements of an array to their initial (unassigned) values.
In short, Erase
“clears out” or
empties an array.
Rules at a Glance
Specify more than one array to be erased by using commas to delimit
arraylist
.Fixed array variables remain dimensioned; on the other hand, all memory allocated to dynamic arrays is released.
After the
Erase
statement executes,TypeName
returns “Variant( )” for a fixed-length array; in addition, theIsEmpty
function returnsTrue
when individual members of the array are passed to it, and comparisons of an individual member of the array with a null string (“”) and with zero both returnTrue
. On the other hand, theTypeName
function returns Empty for a dynamic array, and comparisons of the array with a null string (“”) and zero also returnTrue
.
Programming Tips & Gotchas
Once you use Erase
to clear dynamic arrays, they
must be redimensioned with ReDim
before being used
again. This is because Erase
releases the memory
storage used by the dynamic array back to the operating system, which
sets the array to have no elements.
VBA/VBScript Differences
Because VBA can be strongly typed, the behavior of the
Erase
statement in clearing a fixed array varies,
depending on the array’s datatype. The effect of the
Erase
statement on a fixed variant array in
VBScript is described earlier in the “Rules at Glance”
section.
See Also
Dim Statement ... |
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.