Jump to content
Sign in to follow this  
MrCheese

If... done before, don't do again in the following repeat loops

Recommended Posts

MrCheese

double post

Edited by MrCheese

Share this post


Link to post
Share on other sites
MrCheese

Hi All,

Sorry for the title, not sure how to describe.

 

Basically, I have a function, which I have trimmed down for this purpose. Basically, for when $i = X, and if the trigger $complete = yes is made and that if statement is completed, I want the function to exit for that $i.

See:

$term =8

Func Primary()
    For $i = 0 To UBound($term) - 1
        ; checks if $completes = yes for $i in the past and exits loop and moves to the next $i

        WinActivate($term[$i])
        Sleep(500)
        mouseclick("left",$SetX,$Sety)
        sleep(500)
        Local $finish = PixelGetColor(1100, 926)
        If $finish = $finishC Then
            $complete = "yes"
        Else
            $complete = "no"
        EndIf
        ; funtion does stuff here

        If $complete = "yes" Then
            WinActivate("Initial.xlsx")
            Sleep(1000)
            $oWorkbook2.Sheets($i + 1).Activate
            ; funtion does more stuff here

        EndIf
        WinActivate($term[$i])
        Sleep(2000)
        MouseClick("left", $SetX, $Sety)
    Next
EndFunc   ;==>Primary

 

How can I best log that for $i complete = "yes" previously?

Thanks for your help.

Edited by MrCheese

Share this post


Link to post
Share on other sites
MrCheese

Any thoughts?

Let me know if I need to rephrase my question?

Share this post


Link to post
Share on other sites
VIP

TRY:

Global $term = 8 ; ????????

Global $numYES = -1

Func Primary()
;~  Local $numYES
    For $i = 0 To UBound($term) - 1
        ; checks if $completes = yes for $i in the past and exits loop and moves to the next $i
        If $i = $numYES Then ContinueLoop 
        
        WinActivate($term[$i])
        Sleep(500)
        MouseClick("left", $SetX, $Sety)
        Sleep(500)
        Local $finish = PixelGetColor(1100, 926)
        If $finish = $finishC Then
            $complete = "yes"
        Else
            $complete = "no"
        EndIf
        ; funtion does stuff here

        If $complete = "yes" Then
            WinActivate("Initial.xlsx")
            Sleep(1000)
            $oWorkbook2.Sheets($i + 1).Activate
            ; funtion does more stuff here
            $numYES=$i
            
        EndIf
        WinActivate($term[$i])
        Sleep(2000)
        MouseClick("left", $SetX, $Sety)
    Next
EndFunc   ;==>Primary

 

Edited by Trong
-1

Regards,
 

Share this post


Link to post
Share on other sites
MrCheese

Thanks for your reply..

wouldn't I need to add something within this IF statement?

If $complete = "yes" Then
            WinActivate("Initial.xlsx")
            Sleep(1000)
            $oWorkbook2.Sheets($i + 1).Activate
            ; funtion does more stuff here
            
        EndIf

As that is the component that when entered causes the skip for $i in the next loop.

Share this post


Link to post
Share on other sites
VIP

YES: $numYES=$i    (I fix and forget it!)


Regards,
 

Share this post


Link to post
Share on other sites
MrCheese

Thanks,

when I run this, it skips when $i = 0, as $term[$i] appears where $i = 1 and not $=0

does that make sense?

If i remove, if $i = $numYES then continue loop, then the funtion behaves normally.

Any thoughts?

 

Func Primary()
    For $i = 0 To UBound($term) - 1
        if $i = $numYES then ContinueLoop
        ToolTip("Opening Terminals, terminal: " & $i, 100, 4)
        WinActivate($term[$i])
        WinWait($term[$i])
        Sleep(100)
        MouseClick("left", $SetX, $Sety)
        Sleep(200)
        ToolTip("Colour Check", 100, 4)
        Local $finish = PixelGetColor(1100, 926)

 

Share this post


Link to post
Share on other sites
VIP

try change: Global $numYES to Global $numYES=-1


Regards,
 

Share this post


Link to post
Share on other sites
MrCheese

Spot on :) champ - thank you

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  

  • Similar Content

    • TheGreatMomo
      By TheGreatMomo
      Here is the script for the variable I want to find:
      Local $oSunHrsTD = _IETagNameGetCollection($oFrameobj, "span").item(138)
      The Item(138) for the span elemets is a dynamic number based on the index of all span objects on the webpage I am trying to send inputs to. 
      Based on the span.item(#) the corresponding InnerText for that element is the value that I want to get. Which I use the following script:
      Local $oSunHrs = $oSunHrsTD.InnerText
      Global $otime = _IECreate ("https://somewebsite.banana") _IELoadWait($otime) Local $oFrameobj = _IEFrameGetObjByName($otime, "gsft_main") Local $oLinks = _IETagNameGetCollection($oFrameobj, "a") For $oLink In $oLinks If $oLink.ClassName = "linked formlink" Then _IEAction($oLink, "click") ExitLoop EndIf Next _IEloadWait($oFrameobj) Local $oMonHrsTD = _IETagNameGetCollection($oFrameobj, "span").item(139) Local $oMonHrs = $oMonHrsTD.InnerText _IELoadWait($oFrameobj) Local $oFrameobj = _IEFrameGetObjByName($otime, "gsft_main") Local $oMonHrs = _IETagNameGetCollection($oFrameobj, "SPAN") For $oMonHr In $oMonHrs If $oMonHr.ClassName = "aggregate_value" Then If $oMonHr.innertext >= "8" Then Local $oMonAdjHr = (8 - $oMonHR.Innertext) ConsoleWrite( $oMonHrs &@CRLF ) MsgBox (0, "Adjusted Value", $oMonAdjHr) ExitLoop EndIf EndIf Next  
      Where I get confused is how I find Item(#) if all I have is the InnerText. Since the InnerText is static and the Item# is dynamic:
      $oSunHrsTD = _IETagNameGetCollection($oFrameobj, "span").item( "x").InnerText = ("sometext")
      How can i get the X value??
       
    • Vikramjeet
      By Vikramjeet
      $oExcel = ObjCreate("Excel.Application") $oExcel.Visible = 0 #include <MsgBoxConstants.au3> #Include <File.au3> Global $arlines WinActivate("MyApplication") ;Activate My Application Local $hWnd = WinWaitActive("MyApplication", "", 5) ;Wait for My Application for 5 seconds $oExcel.Application.WorkBooks.Open("C:\Users\Charlie\Desktop\Data.xlsx") ;Open Excel file 'Data.xlsx' local $iCell = $oExcel.Application.Cells(31,1).Value ;Read the value from cell A31 $file = @ScriptDir & "\Capture.log" If $hWnd Then For $a = 1 to $iCell ;STEP 1 Send("G*L") Send($oExcel.Application.Cells($a,1).Value) Send("/XUSR") Sleep(1000) Send("{ENTER}") Sleep(2000) ;===> Once the script has sent the above formats to 'MyApplication, A log file (Capture.log) is generated. What do I add as a link so the script moves to ;the following steps _FileReadToArray ($file, $arlines) For $i = $arlines [0] To 1 Step - 1 ; Script starts reading the log file from bottom up If $arlines [$i] = "‡NOT VALID" Then ;===> If I find the word '‡NOT VALID', then I want the script to go to STEP 1 in loop Else ;====> Else I want the script to do the following steps Send("MB") ; Continue sending formats to 'MyApplication' Send("{ENTER}") Sleep(2000) $iNum = StringRegExp(FileRead($file), "(?sm).*^\h*(\d{1,3})", 1)[0] ; Read number at a certain location in Capture.log file ConsoleWrite($iNum & @CRLF) EndIf ;====> Use the captured $iNum in the loop below. What do I add to proceed to the following steps For $i = 1 To $iNum Send("SET"& $i &"/USR") Sleep(500) Send("{ENTER}") Sleep(1000) ;====> Go back to STEP 1 $oExcel.Application.Quit I am a beginner and need help with If, then, else jump to specific loop in the script. Can I please get help with my script where I have multiple loops. I need to link the steps and also break the sequence and jump to specific loop if a certain condition is found in one loop. 
    • Skeletor
      By Skeletor
      Hi Guys,
      Is it possible to get a variable on your For..Next loop? 
       
      Local $Lines1 = _FileCountLines(C:\temp\test.txt) Local $linesToCount2 = $Lines1 + 2 $var = Number($linesToCount2) For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = $var To $count Next ;Code does stuff here Next Somehow my code doesn't work even though I thought I could convert the variable to a Integer / Number.
      This code I posted above does not move to the next value.
      But the code below does... why is that?
      For $count = 1 To _FileCountLines($FileRead2) Step 1 For $i = 2 To $count Next ;Code does stuff here Next  
      Why is the For loop resetting itself?
      Is it because the program does not cache the variable and needs to keep on acquiring this variable each time?
      If so , how would you make this variable static?

       
    • milkmoron
      By milkmoron
      Hi is there a move next function or a way to loop so that the next item in a record is selected? I'm not sure where to start looking in order to find them. I want to click a text link and then do my macros, which I'm already finished with and then make it move to the next record. This is on a web browser it looks like this. The link is a date. I believe the page uses javascript Theres also a button for the bottom and I want it to do a whole date range 1/1/2016 - 7/1/2018

    • MrCheese
      By MrCheese
      hi all,
      Dumb question, but say I have a loop:
      dim $i Do     sleep(1000)          if $i = ; how do i do a function that enters this IF statement every 10 loops?         ; do stuff every 10     EndIf      Until $i = 100  
      - what commands in the if statement do I need to use to make it pass, and on every 10th loop, it enters the if statement. ?
       
      Thanks
×