Jump to content

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


Recommended Posts

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

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,
 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)

 

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

×
×
  • Create New...