Sign in to follow this  
Followers 0
newbiescripter

Problems with _ArrayDelete... Please Help

9 posts in this topic

Hello

I'm almost finish with my script, but then when i tested it i ran into some errors cause by the information in the array.

Now i want to remove these, but when it's done it's come up with this error:

REMOVEerrorfirst.au3 (85) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

I have this code:

For $x = 1 To UBound($Image) - 1
    For $y = 1 To 12
        If $Image[$x][$y] <> "mega" And  $Image[$x][$y] <> "kilo" Then
        _ArrayDisplay( $Image, "Before" )
        _ArrayDelete( $Image,$x)
        _ArrayDisplay( $Image, "After" )
        EndIf
    Next
Next

And then this error comes:

REMOVEerrorfirst.au3 (85) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
If $Image[$x][$y] <> "mega" And  $Image[$x][$y] <> "kilo" Then
If ^ ERROR

I've read about some of the problems here:

http://www.autoitscript.com/forum/index.ph...hl=_arraydelete

http://www.autoitscript.com/forum/index.ph...c=18211&hl=

But I can't make it work. cause I'm nore sure that I've understanded it right. Everything I do is wrong.

Hope that you can help me :)

Thanks

Share this post


Link to post
Share on other sites



Builtin _ArrayDelete is for one-dimensional arrays.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Okay.. I thought so, but wasn't sure what else to do.

Do you know how I could use the Array2D.au3 as Randallc describes ?

I was thinking.. can I call it for one dimension, when I want it to delete the whole $x and not only a [$x][$y] ?

because it's the whole row I want to delete.

Edited by newbiescripter

Share this post


Link to post
Share on other sites

You are going to have problems with this even if you do get ArrayDelete working and here is why.

Lets say you have this:

$array[3] = ["Red", "Blue", "Green"]

;Loop from $X = 0 to 2
For $X = 0 to Ubound($array) - 1
    If $array[$X] = "Blue" Then
        _ArrayDelete($array, $X) ;This will delete the second array element AND redimension the array to ["Red","Green"]
    EndIf
Next

This will cause a subscript error, you don't want to resize an array whilst in the middle of a loop. The loop will attempt to access the third element ($X = 2) and crash. Do you see what I mean? You need to rethink your logic.

Share this post


Link to post
Share on other sites

I see, but can I fix it with randallc's Array2D.au3 ??

Share this post


Link to post
Share on other sites

Hi,

OK,

You can always use your own -ArrayDelete2D,

but this shows the logic and works; as long as I have understood your logic!

You need to step through backwards if deleteing, sa @WeaponX points out, and also leave the loop on subitems if you dlete a row;

Best, randall

;Array2DDeleter.au3
#include<array2d.au3>
Local $aImage[3][3] = [[30, 31, 32], [10, 11, 12], [21, 22, 23]]
_ArrayDisplay($aImage, "Before")
For $x = UBound($aImage, 1) - 1 To 0 Step - 1
    For $y = 0 To UBound($aImage, 2) - 1
        If $x > UBound($aImage, 1) - 1 Then ;ExitLoop
            ConsoleWrite("Array has been shrunk, so exit loop" & @LF)
            ExitLoop
        EndIf
        If $aImage[$x][$y] >=30  Or $aImage[$x][$y] <=20 Then
            ConsoleWrite("Don't delete as all items either >=30 or <=20 in this line;  continue checking this line; continueloop" & @LF)
;~      If $aImage[$x][$y] == "mega"  Or $aImage[$x][$y] == "kilo"  Then
;~          ConsoleWrite("Don't delete as all items either meg or kilo in this line;  continue checking this line; continueloop" & @LF)
            ContinueLoop
        EndIf
        ConsoleWrite("Before Delete row " & $x & " UBound($aImage, 1):=" & UBound($aImage, 1) & @LF)
        _ArrayDelete2D($aImage, $x)
        ConsoleWrite("After Delete row " & $x & " UBound($aImage, 1) :=" & UBound($aImage, 1) & @LF)
        ExitLoop
    Next
    _ArrayDisplay($aImage, "After loop $x =" & $x)
Next

Share this post


Link to post
Share on other sites

It doesn't comes up with the error anymore, so in that way it's fine :)

but I can't make it delete correctly.. It should be like if it isn't there is anything else in the row under the collums than mega or kilo then it should delete the whole row and then check the next row afterwods..

So when it's done so do I only have "mega" and "kilo" in my array, so I can call it later.

If $aImage[$x][$y] >=30  Or $aImage[$x][$y] <=20 Then

This is the line that I should change right?

I just can't change it to delete the row where there is anything else than "mega" or "kilo".. Hope you understand

Share this post


Link to post
Share on other sites

It doesn't comes up with the error anymore, so in that way it's fine :)

but I can't make it delete correctly.. It should be like if it isn't there is anything else in the row under the collums than mega or kilo then it should delete the whole row and then check the next row afterwods..

So when it's done so do I only have "mega" and "kilo" in my array, so I can call it later.

If $aImage[$x][$y] >=30  Or $aImage[$x][$y] <=20 Then

This is the line that I should change right?

I just can't change it to delete the row where there is anything else than "mega" or "kilo".. Hope you understand

Hi,

Yes, that's why I left your lines in there, ready to reverse the commented lines and comment out my 2 above...

Let me know.

Best, randall

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I made it works.. thanks :)

In the beginning I couldn't understand why it did delete everything, but i just needed to add

Or $aImage[$x][$y] == ""

Because my first colum was blank, doh! ;)

Thanks

Edited by newbiescripter

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