Jump to content

Recommended Posts

Posted (edited)

Hello guy. 

When I delete rows from an array. I come into a problem I never had. 

 

How to do something like that without getting stuck in the script because of

incorrect number of subscripts or subscript dimension range exceeded

 

Here is what I did. But.. I know what is the problem I don't know how or what to use to get out from my error. 

If WinActive ("Tableau de bord Helpdesk") And $SecuAntiFlood > 500 Then
                $SecuAntiFlood = 0
                Sleep (200)
                Send ("^a")
                Sleep (200)
                Send ("^c")
                MouseClick ( "left" , 1600 , 525 , 1 , 10 )

                $iResultsArray = StringSplit ( ClipGet() , @CRLF )

                $iRows = UBound ($iResultsArray)
                $iRows -= 1

                ConsoleWrite ($iRows&@CRLF)
                _ArrayDisplay ($iResultsArray)

                For $i = 0 To $iRows Step 1

                ConsoleWrite ($i&@CRLF)

                    If $iResultsArray[$i] = "" Or $iResultsArray[$i] = " " Then
                        _ArrayDelete ( $iResultsArray , $i )
                        $i -= 1
                    EndIf

                Next

                _ArrayDisplay ($iResultsArray)
            EndIf

So I have 151 rows. 

I want to remove all blank rows. To reduce the amount of rows. 

But If I delete rows from my array of course the number of subscripts will be reduced and my for loop is going to have a number larger than my array rows. 

I tried to play with $iRows... but it does not effect the for loop if $iRows is called before the number won't change for the loop from what I understand. How to do please guys ? 

This is a reproducer that demonstrate my error so don't be rude with the code structure. 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

  Reveal hidden contents

 

  • Moderators
Posted

caramen,

Start from the bottom and work up:

For $i = $iRows To 0 Step -1

That way you never try to access a non-existent row.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

oh ... simple as that xD... Ok trying rn... 

 

It work :) Thanks M23 like always :) 

Happy Christmas. 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

  Reveal hidden contents

 

Posted (edited)

@Melba23 I don't get it. 

My return console write isn't expected : 

If WinActive ("Tableau de bord Helpdesk") And $SecuAntiFlood > 500 Then
                $SecuAntiFlood = 0
                Sleep (200)
                Send ("^a")
                Sleep (200)
                Send ("^c")
                MouseClick ( "left" , 1600 , 525 , 1 , 10 )

                $iResultsArray = StringSplit ( ClipGet() , @CRLF )

                $iRows = UBound ($iResultsArray)
                $iRows -= 1

                ConsoleWrite ("$iRows = "&$iRows&@CRLF)
                _ArrayDisplay ($iResultsArray)

                For $i = $iRows To 0

                ConsoleWrite ($i&@CRLF)
                ConsoleWrite ("Array 8"&@CRLF&$iResultsArray[8]&@CRLF)

                    If $iResultsArray[$i] = "" Or $iResultsArray[$i] = " " Or $iResultsArray[$i] = @CRLF Then
                        _ArrayDelete ( $iResultsArray , $i )
                        $i -= 1
                        ContinueLoop
                    EndIf

                Next
                ConsoleWrite ("$iRows After loop = "&$iRows&@CRLF)
                _ArrayDisplay ($iResultsArray)
            EndIf
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\caram\OneDrive\Autoit\Projet Menu contextuel\Menu contextuel 7.0\Final\Menu contextuel 7.6.2.au3"     
$iRows = 151
$iRows After loop = 151
+>13:44:18 AutoIt3.exe ended.rc:0

151 = $iRows

It is like $iRows = 0 -.-

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

  Reveal hidden contents

 

Posted

Arggggg I had to use a negative step. 

 

For $i = $iRows To 0 Step -1

Thanks ^^

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...