Jump to content

For loop and _ArrayDelete


caramen
 Share

Recommended Posts

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

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

  • Moderators

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

@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

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

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

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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