当前位置: 首页 > 文档资料 > VBA 中文教程 >

Erase

优质
小牛编辑
135浏览
2023-12-01

擦除功能用于重置固定大小数组的值并释放动态数组的内存。 它的行为取决于数组的类型。

语法 (Syntax)

Erase ArrayName
  • 固定数字数组,数组中的每个元素都重置为零。
  • 固定字符串数组,数组中的每个元素都重置为零长度“”。
  • 对象数组,数组中的每个元素都重置为特殊值Nothing。

例子 (Example)

添加按钮并添加以下功能。

Private Sub Constant_demo_Click()
   Dim NumArray(3)
   NumArray(0) = "VBScript"
   NumArray(1) = 1.05
   NumArray(2) = 25
   NumArray(3) = #23/04/2013#
   Dim DynamicArray()
   ReDim DynamicArray(9)   ' Allocate storage space.
   Erase NumArray          ' Each element is reinitialized.
   Erase DynamicArray      ' Free memory used by array.
   ' All values would be erased.
   msgbox("The value at Zeroth index of NumArray is " & NumArray(0))
   msgbox("The value at First index of NumArray is " & NumArray(1))
   msgbox("The value at Second index of NumArray is " & NumArray(2))
   msgbox("The value at Third index of NumArray is " & NumArray(3))
End Sub

执行上述功能时,会产生以下输出。

The value at Zeroth index of NumArray is 
The value at First index of NumArray is 
The value at Second index of NumArray is 
The value at Third index of NumArray is