Jump to content
Sign in to follow this  
icu

How do I start a loop through an array at different points? [solved]

Recommended Posts

Dear AutoIt Community,

I'm not having any luck figuring out a way that will let me start a loop through an array at different points in the array.

Say I have an array called $av_Array and at this particular time I need the loop to start at $av_Array[159] and continue until it gets to UBound($av_Array). Next time I run the program I might need it to start at $av_Array[5689] and continue until it gets to UBound($av_Array)... how would I go about this?

Compounding my problem is that I have 3 sets of nested loops, the top two of which I'll need to set the loop entry point for.

Any and all help is greatly appreciated.

Kind regards,

icu

Edited by icu

Share this post


Link to post
Share on other sites

I don't know if it helps, but you can try:

Func _LoopArray($aArray, $iStart=0, $iEnd="")
If $iEnd="" Then $iEnd=UBound($aArray)-1
For $i=$iStart To $iEnd
;Do something
Next
EndIf

Share this post


Link to post
Share on other sites

@taietel: Thank you very much for your help! Your idea works perfectly... I've only changed the EndIf to EndFunc ;-)

Func _LoopArray($aArray, $iStart=0, $iEnd="")
If $iEnd="" Then $iEnd=UBound($aArray)-1
For $i=$iStart To $iEnd
  ;Do something
Next
EndFunc ;==> _LoopArray
Edited by icu

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By goku200
      I'm having some issues with writing to column C when an element is found. It works on C2 but it does not continue to C3, C4, C5, etc..... I'm wanting to write "test" if the element //input[@id='username'] is found  $someUser = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='username']"). I have attached my HTML and Excel file along with my AutoIt code below:
      #Include "wd_core.au3" #Include "wd_helper.au3" #Include "wd_core.au3" #Include "File.au3" #Include "Array.au3" #Include "Excel.au3" Local $sDesiredCapabilities, $sSession _WD_Startup() $Ssession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://127.0.0.1/test.html") _WD_LoadWait($sSession) Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\<Username>\Downloads\test.xlsx") Local $aArrayTest1 = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local $aArrayTest2 = _Excel_RangeRead($oWorkbook, 1, $oWorkbook.ActiveSheet.Usedrange.Columns("B:B")) For $i = 0 To UBound($aArrayTest1) - 1 _WD_Navigate($Ssession, $aArrayTest1[$i]) _WD_LoadWait($sSession) $someUser = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='username']") _WD_SetElementValue($sSession, $someUser, $aArrayTest2[$i]) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@type='submit'][@value='Submit']") _WD_ElementAction($sSession, $sElement, 'click') _WD_LoadWait($sSession) Sleep(5000) If $someUser Then Local $aArray2D[2] = ["test"] _Excel_RangeWrite($oWorkbook, $oWorkbook.ActiveSheet, $aArray2D, "C2") EndIf Next Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome  
      test.html test.xlsx
    • By Vikramjeet
      include-once #include <File.au3> #include <Excel.au3> #include <String.au3> #include <MsgBoxConstants.au3> Local $file = "TEST.log" FileOpen($file, 0) $TTLPax = 1 For $i = _FileCountLines($file) - $TTLPax to _FileCountLines($file) $line = FileReadLine($file, $i) Global $TktNo = StringMid($line, 8, 13) ; reads 13 characters from $Line starting from the 8th character msgbox(0,'',$TktNo) ; This is just for me to debug For $NoOfPax = 1 to 2 local $TTLSeg = 2 msgbox(0,'',$TTLSeg) msgbox(0,'',"7ABC"& $TktNo &"'N"& $NoOfPax &".1'C1,2'S1,2'B") ; This makes 7ABC1234567890123'N1.1'C1,2'S1,2'B ;But in the next loop I want the value to be 7ABC1234567890333'N2.1'C1,2'S1,2'B Next ExitLoop Next *TEST
      JAMES BAKER
        1.NYC-23JAN
        2.TJ 1234567890123
        3.TJ 1234567890333
      I am reading a file with last 5 lines as above. I want to be able to loop through and pick the values as follows
      1- Pick 1234567890123
      2- Use it to build a format with N1.1
      3- Pick 1234567890333
      2- Use it to build a format with N2.1
      Need help with the loop. Thank You
       
       
    • By Vikramjeet
      For $A1 = 12 To 11 + $Total For $B1 = 1 To ($oExcel.Application.Cells($A1,6).Value) ; This value is from the Excel file. It can be from 1 - 9. For $N1 = 7 To ??? ; This is based on the value of $B1 ((1 = 7, 2 = 17, 3 = 27, 4 = 37, 5 = 47) Send("-"& ($oExcel.Application.Cells($A1,$N1).Value) &"/"& ($oExcel.Application.Cells($A1,$N1+1).Value)) Sleep(400) Send("{ENTER}") Sleep(700) Next Next Next I am not able to figure how to loop $N1 as follows
      If the Value of $B1 = 1 then $N1 = 7
      If the Value of $B1 = 2 then $N1 = 17
      If the Value of $B1 = 3 then $N1 = 27
      If the Value of $B1 = 4 then $N1 = 37  
      The value of $N1 comes from $B1 where 1 = 7, 2 = 17, 3 = 27, 4 = 37, 5 = 47)
      Thank You
    • By roeselpi
      hello again,
      it has been a long time since i have been here and a long time since i last used autoit. ever so often when the time allows me to, then i follow up on an idea that i had a long time ago. i have done all the work on paper but now it is up to writing it in autoit and i keep stumbling over many little issues here and there. sometimes after a few days i will try again and get a step further but sometimes it just will not help no matter how long i try and think about a solution. for most of you it will be the basics but for me it is not all that easy, but at least i give it a try.
      right, down to business:
      here is my code:
      #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <String.au3> ; ; PART 1: define replacements and check with msgbox ; Global $y, $z $y = "Yes" $z = "No" MsgBox(0,"replacements", $y & @CRLF & $z) ;the replacements in a message box ; ; PART 2: set the texts and check via console and msgbox ; Global $my1string = "abab" ;the first specified text MsgBox(0,"my1string", $my1string) ;the message box to output the first specified text Global $my2string = "icic" ;the second specified text MsgBox(0,"my2string", $my2string) ;the message box to output the second specified text ; ; PART 3: transform the strings to individual arrays ; $my1array = StringSplit($my1string, "") $my1array[0] = "" _ArrayDelete($my1array, 0) _ArrayDisplay($my1array, "my1array") ;the display of the first specified array $my2array = StringSplit($my2string, "") $my2array[0] = "" _ArrayDelete($my2array, 0) _ArrayDisplay($my2array, "my2array") ;the display of the first specified array ; ; PART 4: create an empty array for filling ; Global $OutputArray[4] $OutputArray[0] = "" _ArrayDisplay($OutputArray, "OutputArray") ;the display of the first specified array ; ; PART 5: compare & fill empty OutputArray with data after evaluation ; Global $i, $j, $k For $i = 0 to UBound($my1array) -1 For $j = 0 to UBound($my2array) -1 For $k = 0 to UBound($OutputArray) -1 If $my1array[$i] = "a" And $my2array[$j] = "i" Then $OutputArray[$k] = $y Else $OutputArray[$k] = $z EndIf Next Next Next _ArrayDisplay($OutputArray, "OutputArray") ;the display of the Newly filled Array In "Part 2" i make a string that is converted to an array in "Part 3" ... Now, I know that "a" and "i" are always in the exact same spot in both arrays and so i wanted to compare this and make a further array to document my findings by saying "yes" or "no" ... however my new array keeps saying just "no" allthough i can clearly see and know that it should say:
      yes no yes no my guess is that there is something wrong within my for-loops and that the counting is somehow "off" i guess that when the first for-loop is finished it reaches the second whilst the second for-loop is checking the first which would explain why it always says "no" instead of seeing the obvious.
      so my question would be: what is wrong with my for-loop? or where am i making an error that ultimately gives me the wrong results?
      help is much appreciated.
      kind regards
      roeselpi
       
       
      PS: sorry for my not so great english spelling ... stupid german sitting here trying out intermediate english skills.
    • By Jangal
      Hello friends
      This app is slow
      How to increase its speed?
       
      #include <Array.au3> #include <StringConstants.au3> #include <File.au3> #include <String.au3> Global $aWord[][2]  = [[1, "google"],[2,"hello"]]


        Global $sFileName = @ScriptDir & "\1.txt" ; 2MB Text File Local $sFileRead = FileRead($sFileName) Local $res = StringRegExp($sFileRead, "(*UCP)\b[\pL\d]{2,}", 3) _ArrayDisplay($res)   for $sWord in $res     $iIndex = _ArraySearch($aWord, $sWord, 0, 0, 0, 0, 1, 2)     ;MsgBox(0,0,$iIndex)     if $iIndex == -1 Then         Local $aFill = [[0,$sWord]]         _ArrayAdd($aWord,$aFill)        ;      Else         $aWord[$iIndex][0] +=1     EndIf   Next _ArrayDisplay($aWord)

      1.txt
×
×
  • Create New...