How to clear the entire array?

前端 未结 8 873
不思量自难忘°
不思量自难忘° 2021-02-02 05:06

I have an array like this:

Dim aFirstArray() As Variant

How do I clear the entire array? What about a collection?

8条回答
  •  梦谈多话
    2021-02-02 05:57

    You can either use the Erase or ReDim statements to clear the array. Examples of each are shown in the MSDN documentation. For example:

    Dim threeDimArray(9, 9, 9), twoDimArray(9, 9) As Integer
    Erase threeDimArray, twoDimArray
    ReDim threeDimArray(4, 4, 9)
    

    To remove a collection, you iterate over its items and use the Remove method:

    For i = 1 to MyCollection.Count
      MyCollection.Remove 1 ' Remove first item
    Next i
    

提交回复
热议问题