Sign in to follow this  
Followers 0
=sinister=

Deleting All Values in an Array

5 posts in this topic

I tired

For $i = 0 To UBound($Keys)
    _ArrayDelete($Keys, $i)
Next

But it always leaves 1 value from the Array (The second value).

Share this post


Link to post
Share on other sites



To delete everything in an array, just say $var = 0. Then the array is gone.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

LOL! A lot more simple than what I had in mind. I made a "Temp" value, then inserted a value, then deleted the "Temp" value. Now I just delete that Array and create a new one, thanks.

Edited by =sinister=

Share this post


Link to post
Share on other sites

Sometimes the simplest answer is the hardest to find.

Share this post


Link to post
Share on other sites

I tired

For $i = 0 To UBound($Keys)
    _ArrayDelete($Keys, $i)
Next

But it always leaves 1 value from the Array (The second value).

Your current issue is solved, thanks to Richard, but you have other problems here that will bite you in the future:

Any time you will be walking an array deleting elements, you should be working through it BACKWARDS because deleting an element changes the index number of the following elements. Also, Ubound() returns the 1-based count of elements, but array are 0-based requiring the use of "Ubound($avArray) - 1". So, though the point is moot for now, your code should have been:

For $i = UBound($Keys) - 1 To 0 Step -1
    _ArrayDelete($Keys, $i)
Next

As Richard showed, this is not the easiest way simply delete the array, but when you want to selectively delete SOME elements, this technique is required to avoid errors.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0