Sign in to follow this  
Followers 0
MrCheese

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

9 posts in this topic

#1 ·  Posted (edited)

double post

Edited by MrCheese

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

#3 ·  Posted

Any thoughts?

Let me know if I need to rephrase my question?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

#5 ·  Posted

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

#6 ·  Posted

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


Regards,
 

Share this post


Link to post
Share on other sites

#7 ·  Posted

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

#8 ·  Posted

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


Regards,
 

Share this post


Link to post
Share on other sites

#9 ·  Posted

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  
Followers 0

  • Similar Content

    • 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
    • Razormaul
      By Razormaul
      This is a repost, since the thread was deleted due to database issues. - https://www.autoitscript.com/forum/topic/173518-thread-deleted/
       
      Hello fellow geeks
      I am making a small program for work, a tool with shortcuts and host monitoring.
      The program has several tab and  I need help with the tab called "Servers/Hosts"
      The tab reads hostnames or ip adresses from an ini file and writes them to a listview. You can add or remove hosts, ping, connect with mstsc and delete the whole list. Now...
      Im checking for ip adresses on start of the program, or with a refresh button - so far so good.. It´s working.
      I also have a function to check if a host is online and write it to the listview, but i cant make it work (im not good enough yet) - (ALMOST SOLVED -  Writing a dummyhost e.g. "test" as hostname, gets the status "Online" - im currently working on that )
      This check needs to run every 10 seconds or so, among with the check for ip adresses. But again, (im not good enough yet) - (SOLVED USING AdlibRegister)
      I´ve tried to put the functions in a loop in different places in the script. They either "block" the script or hide it.
      If i can get the loop to work, there is no need for a refresh button. and i want to put the foldercheck in the VIKING tab in a similar loop, displaying a warning instead of having to click a button. (but thats a different question)
      I hope one of you briliant minds can help me along the way:) Thank you for your time.
      Tobias
       
       
      IT-Tools.V13.au3
      Servers.ini