Sign in to follow this  
Followers 0
BlueScreen

Forgot How To Delete An Array Element

10 posts in this topic

Hey,

I have forgotten how to delete an array element... :whistle:

Share this post


Link to post
Share on other sites



Dim $array[10]

to delete it I just

$array = ""

Lar.

Does that actually free the memory for the array, though? The helpfile says $array = 0 will free it...

Share this post


Link to post
Share on other sites

10x Larry, but is there a possibility to delete an element?

Dim $x[3]

$x[0]=1

$x[1]=2

$x[2]=3

How to delete $x[2] ?

Share this post


Link to post
Share on other sites

Or to delete one element, just over write it.

Dim $x[3]

$x[0]=1

$x[1]=2

$x[2]=3

How to delete $x[2] ?

$x[2]=""


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Or to delete one element, just over write it.

Dim $x[3]

$x[0]=1

$x[1]=2

$x[2]=3

How to delete $x[2] ?

$x[2]=""

I think he means make it go away totally.

$x[0] = 3

$x[1] = 2

$x[2] = 1

Now delete $x[1] and you have this:

$x[0] = 3

$x[1] = 1

$x[2] = No longer exists, so it would be out of bounds.

BlueScreen, you have 2 options. One is to either check to make sure the element isn't empty before you act on it, this will allow you to use scriptkitty's solution of just assigning "" to the element. The other is to design some functions and stuff to implement your own container or something.

Share this post


Link to post
Share on other sites

10x scriptkitty, but when running "Ubound", it keeps showing 3 elements instead of 2 !

Dim $x [3]
$x[0]=1
$x[1]=2
$x[2]=3

$x[2]=""
msgbox (0,"",Ubound ($x)); Should result 2, no?

Share this post


Link to post
Share on other sites

10x, Valik,

You understood me.

I wan't to modify the size of an array dynamically by deleting an element.

Is it possible?

Share this post


Link to post
Share on other sites

Does that actually free the memory for the array, though?  The helpfile says $array = 0 will free it...

Assigning anything to the whole array will free it and turn in back into a single value.

Share this post


Link to post
Share on other sites

B) OK. So I'll overwrite the array with the new params.

10x everybody... :whistle:

Share this post


Link to post
Share on other sites

Assigning anything to the whole array will free it and turn in back into a single value.

Very good point you make. :whistle:

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