Results 1 to 9 of 9

Thread: Clearing an integer array... what value should be used? [SOLVED]

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Clearing an integer array... what value should be used? [SOLVED]

    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.
    Last edited by hothead; Feb 2nd, 2003 at 02:56 PM.

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    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:
    1. Set arrNum(i) = Nothing

  3. #3

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    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.

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Thenjust give them value 0...or something....

  5. #5
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    I could be wrong but->

    wouldn't you just use the following line of code?

    Erase arrNum40

  6. #6
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    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.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  7. #7

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692
    I wrote a function that re-initializes it automatically using ReDim Preserve, so that won't be a problem. Thanks for the info.

  8. #8
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    Erase->

    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.

  9. #9
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: Erase->

    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.
    Dynamic arrays are cleared - you have to ReDim 'em. So your second example wouldn't work if your array was dynamic.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width