I know you need to loop through the array, I just need to know what value I should set each element in the array to. The name I used for the array is arrNum40, which has 40 elements.
I know you need to loop through the array, I just need to know what value I should set each element in the array to. The name I used for the array is arrNum40, which has 40 elements.
What kind of array. If it is only one of the common used datatypes you don't have to clear them out before ending your app if that is what you are thinking of. But if it is an array of objects then you should set them to "Nothing"
like:
VB Code:
Set arrNum(i) = Nothing
It's an integer array. Actually I was thinking about making a game with 3 rounds, and after each round is over, it clears the array and starts the new round.
Thenjust give them value 0...or something....
wouldn't you just use the following line of code?
Erase arrNum40
That would free the memory being used tho and resize it to zero elements, so he would need to re-initialise it aswell. Mind if its going to be a different size or is very big I guess it would be better, as long as he is wanting to clear all elements.
I wrote a function that re-initializes it automatically using ReDim Preserve, so that won't be a problem. Thanks for the info.
If Erase would reset arrays to zero elements, this
code shouldn't work right?
Dim TestArray(10)
Debug.Print TestArray(5)
Erase TestArray
Debug.Print TestArray(5)
Erase doesn't seem to reset the array to zero
elements but simply clear the elements.
Dynamic arrays are cleared - you have to ReDim 'em. So your second example wouldn't work if your array was dynamic.Quote:
Originally posted by Peter Swinkels
If Erase would reset arrays to zero elements, this
code shouldn't work right?
Dim TestArray(10)
Debug.Print TestArray(5)
Erase TestArray
Debug.Print TestArray(5)
Erase doesn't seem to reset the array to zero
elements but simply clear the elements.