How to clear the entire array?

前端 未结 8 890
不思量自难忘°
不思量自难忘° 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条回答
  •  猫巷女王i
    2021-02-02 05:54

    Find a better use for myself: I usually test if a variant is empty, and all of the above methods fail with the test. I found that you can actually set a variant to empty:

    Dim aTable As Variant
    If IsEmpty(aTable) Then
        'This is true
    End If
    ReDim aTable(2)
    If IsEmpty(aTable) Then
        'This is False
    End If
    ReDim aTable(2)
    aTable = Empty
    If IsEmpty(aTable) Then
        'This is true
    End If
    ReDim aTable(2)
    Erase aTable
    If IsEmpty(aTable) Then
        'This is False
    End If
    

    this way i get the behaviour i want

提交回复
热议问题