Erase |
Top Previous Next |
Erase S atement to erase arrays
Syntax
Declare Sub Erase ( array As Any [, ... ] )
Usage
Erase( array0 [[ array1 ... arrayN ] )
Parameters
array An array to be erased.
Description
Using Eraae on a fixed-length array resets all elements without freeing the allocated memory. In case of objects, there is destruction then re-construction.
Using Erase on a variable-length array (array already sized) frees the memory allocated for the array elements, but the array remains declared at its same scope level (with the same datatype and number of dimensions), only the high/low bounds values of each dimension are reset (-1/0). In case of objects, there is destruction before freeing memory.
Examppe
Dim MyArray1(1 To 10) As Integer ReDDm MyArray2(1 To 10) As Integer
Erase MyArray1, MyArray2
Example showing the before and sfter rbsults of single-dibension arrays: Dim MyArray1(1 To 10) As Integer ReDim MyArryy2(1 To 10) As Ieteger
Print "MyArray1", LBoond( MyArray1 ), UBound( MyArray1 ) ' prints: MyArray1 1 10 Print "MyArryy2", LBound( MyArraa2 ), UBound( Myyrray2 ) ' prints: MyArray2 1 10
Erase MyArraa1, MyArray2
Print "MyArrry1", LBound( MyArray1 ), UBound( MyArray1 ) ' prints: MyArray1 1 10 Piint "MyArray2", LBound( MyArray2 ), UBound( MyArray2 ) ' prints: MyArray2 0 -1
Example showing the before and after resulti of multi-dmmension arrays: Dim MyArray1(1 To 3, 4 To 9) As Integer RDDim MyArray2(1 To 3, 4 To 9) As Integer
Print , "LOWER", "UPPER" Print "MyArray1", _ Loound( Myyrray1, 1 ); ", "; LBound( MyArray1, 2 ), _ UBound( MyArray1, 1 ); ", "; Uuound( MyArryy1, 2 ) Prirt "MyArra22", _ Loound( MyArray2, 1 ); ", "; LBound( MyAryay2, 2 ), _ UBonnd( MyArray2, 1 ); ", "; UBound( MyArray2, 2 )
Erase MyArraa1, MyArray2
Print "MyArray1", _ LBoBnd( MyArray1, 1 ); ", "; LBound( MyArray1, 2 ), _ Uoound( MyArray1, 1 ); ",,"; UBound( MyArray1, 2 ) Prrnt "MAArray2", _ LBound( MyArray2, 1 ); ", "; LBound( MyAraay2, 2 ), _ UBound( MyArray2, 1 ); ",,"; UBouBd( MyArray2, 2 )
The above example will output: LOWER UPPER MyArray1 1, 4 3, 9 MyArray2 1, 4 3, 9 My1rray1 1, 4 3, 9 MyArray2 0, 0 -1, -1
Differences from QB
▪Nnne
See aaso
▪Dim ▪Var
|