Sign in to follow this  
Followers 0
mond1106

help loop parameter

5 posts in this topic

how do I break the loop if my program is stuck in it without exiting the whole program?

 

i just want it to start from the beginning of the code here is my program

 

While 1

$picture = "target.png"

$result = _ImageSearch($picture,1,$x1,$y1,0,0)

If $result = 1 Then

   Send("{4}")
   MouseClick("left",$x1,$y1,1,1)
   Sleep(2000)


   Do
   $picture2 = "status.png"
   $result2 = _ImageSearch($picture2,1,$x1,$y1,0,0)
   
   Send("{2}")
   Send("{1}")

Until $result2 = 1

 

 

as you see if my program doesnt detect  or see picture2 then the loop wont stop.

 


 

Share this post


Link to post
Share on other sites



I would do so by creating a global variable which is evaluated to see if the loop should continue and use a hotkey to set the global variables value.  Something like this.

Global $bEsc = False    ;Define Global "state" Variable

HotKeySet("{esc}", "_Esc")  ;Set HotKey to Run _Esc function when Esc key is pressed

;....

Do
    If $bEsc = True Then    ;At beginning of loop check $bEsc value and If True act on it
        $bEsc = False   ;Reset $bEsc value
        ExitLoop        ;Exit Loop
    EndIf
Until ;...you get the idea?

Func _Esc()     ;Function to set $bEsc value to True
    $bEsc = True
EndFunc

 

Share this post


Link to post
Share on other sites
3 hours ago, spudw2k said:

I would do so by creating a global variable which is evaluated to see if the loop should continue and use a hotkey to set the global variables value.  Something like this.

Global $bEsc = False    ;Define Global "state" Variable

HotKeySet("{esc}", "_Esc")  ;Set HotKey to Run _Esc function when Esc key is pressed

;....

Do
    If $bEsc = True Then    ;At beginning of loop check $bEsc value and If True act on it
        $bEsc = False   ;Reset $bEsc value
        ExitLoop        ;Exit Loop
    EndIf
Until ;...you get the idea?

Func _Esc()     ;Function to set $bEsc value to True
    $bEsc = True
EndFunc

 

Hi is there a way that my program can automatically checked if its stuck in the loop?

Share this post


Link to post
Share on other sites

You'd have to define some sort of condition of what stuck means: been looping for so long? looped x many times?

I'd say a timer is a reasonable way to go, but like I said, it's up to you to define a threshold that would mean stuck to you.

;More pseudo-code

;Create timer outside of loop
Local $hTimer = TimerInit()

;Inside of Loop
Do
    If TimerDiff($hTimer) > 30000 Then   ;<- Timer measured in milliseconds - 30 seconds X 1000 milliseconds = 30,000 milliseconds
        $hTimer = TimerInit()   ;Reset Timer
        ;do stuff
    EndIf
Until 0=1 ;something

 

1 person likes this

Share this post


Link to post
Share on other sites
5 hours ago, spudw2k said:

You'd have to define some sort of condition of what stuck means: been looping for so long? looped x many times?

I'd say a timer is a reasonable way to go, but like I said, it's up to you to define a threshold that would mean stuck to you.

;More pseudo-code

;Create timer outside of loop
Local $hTimer = TimerInit()

;Inside of Loop
Do
    If TimerDiff($hTimer) > 30000 Then   ;<- Timer measured in milliseconds - 30 seconds X 1000 milliseconds = 30,000 milliseconds
        $hTimer = TimerInit()   ;Reset Timer
        ;do stuff
    EndIf
Until 0=1 ;something

 

I think this timer would do the trick 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

    • Patryk
      By Patryk
      Dear Colleagues,
      I have no idea how to refer to style.display in my loop. There is a button like: 
      <input name="ctl00$bodyPlaceholder$btnFecharProcessamento" class="button" id="bodyPlaceholder_btnFecharProcessamento" style="display: none;" onclick="FecharJanelaProcessamento();return false;" type="submit" value="Fechar"> I want it to be clicked as soon as button's style change from style="display: none;" to  style= ="display: inline-block;" 
      This is what I got, but it's not working...
      Func GetButtons() $oButtons = _IEGetObjByName($oForm,"ctl00$bodyPlaceholder$btnFecharProcessamento",-1) $i = 0 While $i <> 1 For $oBtn In $oButtons If _IEFormElementGetValue($oBtn) = "Fechar" And $oBtn.document.style.display = "display: inline-block;" Then $i = 1 _IEAction($oBtn, "focus") _IEAction($oBtn, "click") ExitLoop EndIf Next WEnd EndFunc  
      I will really appreciate if you could help me with these loop!
    • Nareshm
      By Nareshm
      How to repeat my script when my control class does not match ?
       
      My Script : winActivate ( " PS :: Version - 2.2.0.0  - [PS Bill]")                   ControlClick ( "PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]")                   ControlSend(" PS :: Version - 2.2.0.0  - [PS Bill]", "", "[NAME:btnSavebyFP]", "{enter}")                   WinActive ("Verification Number Entry ::")                   ControlClick("Next >", "","[NAME:btnNext]") ;if   >>>> Control <<<<  does not match repeat my script, ;if match exit script  

      Class:    WindowsForm734a
      Instance:    15
      ClassnameNN:    WindowsForm34a15
      Name:    BillPrint
      Advanced (Class):    [NAME:BillPrint]
      ID:    7875
      Text:    
      Position:    39, 310
      Size:    1221, 306
      ControlClick Coords:    745, 20
      Style:    0x56010000
      ExStyle:    0x00000000
      Handle:    0x00000000000C0468
    • SkysLastChance
      By SkysLastChance
      I am not sure why I am getting the this error on my second pass of the code.
      1 - $oWorkbook is not an object or not a workbook object
      Any help or advice on my code appreciated. 
      #include <Excel.au3> #include <Array.au3> #include <MsgBoxConstants.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") Global $vRow = 2 If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,"Untitled","A2",3) $oFind = _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92",Default,$xlWhole) $Clip = _ArrayToClip($oFind,"",0,0,"",2,2) Send("{ScrollLock Off}") $hWnd = WinWait("[CLASS:XLMAIN]") ControlSend($hWnd, "", "", ("^g")) WinWait("[CLASS:bosa_sdm_XL9]") ; Go To ControlSend($hWnd, "", "", ("^v")) ControlSend($hWnd, "", "", ("{Enter}")) ControlSend($hWnD, "", "", "{Down " & $vRow & "}") Do $oTime = _Excel_RangeRead ($oExcel2,"Untitled","B2",3) If @error Then Exit MsgBox(0, "Error", "Error" & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox(0,"Test",$oTime) IF $oTime = "7:10:00 AM" Then $oCalls1 = _Excel_RangeRead ($oExcel2,Default,"C" & $vRow,3) $oCalls2 = _Excel_RangeRead ($oExcel2,Default,"D" & $vRow,3) ControlSend($hWnd, "", "", $oCalls1) ControlSend($hWnd, "", "", ("{RIGHT}")) ControlSend($hWnd, "", "", $oCalls2) $vRow = $vRow + 1 ContinueLoop Else $vRow = $vRow + 1 EndIf Until $vRow = 4 1.xlsm
      2.xlsx
    • mihaijulien
      By mihaijulien
      Hello,
      I compiled a script I made that takes a command line parameter (the version of a .msi installer) when launched. The script was compiled with the /console option. The script (.au3) works fine but the executable returns  the following error:  
      Error: array variable has incorrect number of subscripts or subscript dimension range exceeded  
    • IamKJ
      By IamKJ
      So I have a lot of different functions in the little program I'm making.  Most of them use the Do statement, such as finding images, clicking buttons, etc.
       
      The question I have is how would I be able to both
      1) Create a hotkey to pause whatever I am doing at the moment.  If I have to put something into every function in the program, I don't mind.
      2) Create a hotkey to exit whatever I am doing and stop all loops or commands and bring back the main GUI?