Sample code
1, for the static array demo
The code is as follows |
Copy Code |
Sub Test1 () Dim ARR (0 to 9) as Integer For i = 0 to 9 ARR (i) = i Next For i = 0 to 9 Debug.Print Arr (i) Next ' Above will output 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 in Immediate window Erase ARR For i = 0 to 9 Debug.Print Arr (i) Next ' Above will output 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 in Immediate window End Sub
|
You can see that the erase statement cleans up the values of the static array.
VBA Cleanup Array
2, for the dynamic array demo
The code is as follows |
Copy Code |
Sub Test2 () Dim ARR () as Integer ReDim ARR (9) Debug.Print UBound (ARR) Debug. Print Erase (ARR) Debug.Print UBound (ARR) ' here will be an error ' Because the dynamically allocated memory has been released End Sub
|
You can see that the erase statement frees up the memory we allocate to the dynamic array.
Original from: http://iofai.com/1305.html thank stationmaster