Name
Erase Statement
Syntax
Erase arraylistarraylistUse: Required
Data Type: 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
Erasestatement executes,TypeNamereturns “Variant( )” for a fixed-length array; in addition, the IsEmpty function returnsTruewhen individual members of the array are passed to it, and comparisons of an individual member of the array with an empty string ("") and with zero both returnTrue. On the other hand, the TypeName function returns Empty for a dynamic array, and comparisons of the array with an empty string ("") and zero also returnTrue.
Programming Tips and 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 data type. The effect
of the Erase statement on a fixed
variant array in VBScript is described earlier in the “Rules at
Glance” section.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access