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

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

    • 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
    • JohnNash
      By JohnNash
      I've seen some weird behavior in my code (I log almost everything).

       
         While 1       $WaitingTime = TimerDiff($wtTimer)       sleep(300)       $Data = TCPRecv($MainSocket, $MaxLength)       _FileWriteLog($LogFolder&"info.log", "Wait for answer that Server is ready for step 21")                            If $Data = "ByeBye" Then                                        _FileWriteLog($LogFolder&"info.log", "Server tells me to shutdown")                                        Terminate()                  ElseIf $Data = "Step 20 Finished on Server" Then                                         _FileWriteLog($LogFolder&"info.log", "Server answers it is ready for step 21")                                         ExitLoop                ElseIf $WaitingTime>4000 Then                                          _FileWriteLog($LogFolder&"info.log", "No Answer, we still continue" &$Data)                                          ExitLoop             EndIf    WEnd    _FileWriteLog($LogFolder&"info.log", "Left the WhileLoop")  
       
      And my logs show this:
       

      2016-10-24 00:52:39 : Wait for answer that Server is ready for step 21

      2016-10-24 00:52:39 : (Logline from completely different loop)
      2016-10-24 00:52:39 : (Logline from completely different loop)
      2016-10-24 00:52:39 : (Logline from completely different loop)
      2016-10-24 00:52:39 : (Logline from completely different loop)

      2016-10-24 00:52:40 : Wait for answer that Server is ready for step 21
      2016-10-24 00:52:40 : Server answers it is ready for step 21
       
      How can this happen? (If there was a "Left the Whileloop" log in between I could imagine it could happen... but now?
      I thought AutoIT was singlethreaded...
       
       
       
       
       
    • Miliardsto
      By Miliardsto
      My function still making spells and ignoring if statement
      -snip-
      And this function returns true and i see spell is entering
    • skyhigh
      By skyhigh
      I am working at a script (thanks @Chimp for the help on my previous thread) operating on Firefox, based on two time-set loops that are doing the same operations with some differences.
      Now I need to execute a local video at a determinated hour (between 12 and 4).  
      My question is
      What is the best way to determine a precise hour (hh:mm)? I tried
      While @Hour >= 12 & @MIN >= 00 And @HOUR <= 14 & @MIN < 30 But the loop is being ignored, although in the moment I use only @Min for my tests everything works fine.
      This is the essential - and working - structure of the present script:
      #include <ff.au3> _FFStart() While @MIN >= 00 And @MIN < 30 ; 1st Firefox loop Firefox url loop (contains functions and if conditions) WEnd ;Open a new tab and runs a local video; While @MIN >= 32 And @MIN <= 59 ; 2nd Firefox loop Firefox url loop (contains functions and if conditions) WEnd Thanks in advance
×