caramen

Exit Active loop

5 posts in this topic

Hello guys.

 

I tryed to follow the process of this tutorial https://www.autoitscript.com/wiki/Interrupting_a_running_function

 

And then so i made that code :

Case $Boutton3 ; Start
                     $SwitchBoutton = GUICtrlRead ($Boutton3)
                        If $SwitchBoutton = "Start" Then
                     Boucle1 ()
                        ElseIf $SwitchBoutton = "Stop" Then
                     Boucle2 ()
                        EndIf
                        
                        
                        
Func Boucle1()
                        $SwitchBoutton = GUICtrlRead ($Boutton3)
                        $TempsInput = GUICtrlRead ($Input2)
                        MsgBox($MB_SYSTEMMODAL, "Check", "The test "&$TempsInput&" is fine.", 10)
                        If $SwitchBoutton = "Start" Then
                           GUICtrlSetData ($Boutton3,"Stop")
                           MsgBox($MB_SYSTEMMODAL, "Check", "The test StartPressedStopEdited is fine.", 10)
                         Sleep (50000)
                        EndIf
EndFunc

Func Boucle2()
                        $SwitchBoutton = GUICtrlRead ($Boutton3)
                        $TempsInput = GUICtrlRead ($Input2)
                        MsgBox($MB_SYSTEMMODAL, "Check", "The test "&$TempsInput&" is fine.", 10)
                        If $SwitchBoutton = "Stop" Then
                           GUICtrlSetData ($Boutton3,"Start")
                           MsgBox($MB_SYSTEMMODAL, "Check", "The test StopPressedStartEdited is fine.", 10)
                        EndIf
EndFunc

I tryed multiple way to stop Boucle1 to run Boucle2 but i dont get it i am sorry.

Could i get some help ?

The best way for me whould be of hit the button Stop to run Boucle2() and Stop Boucle1()

Share this post


Link to post
Share on other sites



Here is the complet script with my last try.

 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>


HotKeySet("{PAUSE}", "Pause")
HotKeySet("{F1}", "Exite")

Global $Paused
Global $Gamesnumber = 0
Global $sComboRead = ""
Global $Boutton3_bis = "0"
Local $hDLL = DllOpen("user32.dll")


;$Picture = @ScriptDir & "\spyfurryMINI.jpg"

Global $SettingsFile = @SCRIPTDIR & '\Settings.ini'
$Setting1 = IniRead ($SettingsFile, 'Stats', 'Utilisation', "ERROR")
$Setting2 = IniRead ($SettingsFile, 'Optionnel', 'Folder1', "ERROR")
$Setting3 = IniRead ($SettingsFile, 'Message', 'Message1', "ERROR")
$Setting4 = IniRead ($SettingsFile, 'Message', 'Message2', "ERROR")
$Setting5 = IniRead ($SettingsFile, 'Message', 'Message3', "ERROR")
$Setting6 = IniRead ($SettingsFile, 'Message', 'Message4', "ERROR")
$Setting7 = IniRead ($SettingsFile, 'Message', 'Message5', "ERROR")
$Setting8 = IniRead ($SettingsFile, 'Pause', 'Temps', "ERROR")
$Setting9 = IniRead ($SettingsFile, 'Boucle', 'Nombre', "ERROR")
$UID1= IniRead ($SettingsFile, 'User', 'User1', "ERROR")
$UID2= IniRead ($SettingsFile, 'User', 'User2', "ERROR")
$Password1 = IniRead ($SettingsFile, 'User', 'Password1', "ERROR")
$Password2 = IniRead ($SettingsFile, 'User', 'Password2', "ERROR")
IniWrite ($SettingsFile, 'Stats', 'Utilisation',$Setting1+1)

;~ GUICreate==================================================
Local $hGUI = GUICreate("Example", 500, 500)

Local $Label1 = GUICtrlCreateLabel ("Entrez le texte a répéter",10,10)
Local $Label2 = GUICtrlCreateLabel ("Pause a respecté",10,70)
Local $Label3 = GUICtrlCreateLabel ("Nombre Boucle",210,70)

Local $Input2 = GUICtrlCreateInput (""&$Setting8,10,100,100,20)
Local $Input1 = GUICtrlCreateInput ("",10,40,480,20)
Local $Input3 = GUICtrlCreateInput (""&$Setting9,210,100,100,20)

Local $Boutton1 = GUICtrlCreateButton ("Set Nombres",400,250)
Local $Boutton2= GUICtrlCreateButton ("Set Message",400,70)
Local $Boutton3 = GUICtrlCreateButton ("Start",220,450)

Local $CheckMessage1 = GUICtrlCreateCheckbox ("Message 1" ,10, 230)
Local $CheckMessage2 = GUICtrlCreateCheckbox ("Message 2" ,100, 230)
Local $CheckMessage3 = GUICtrlCreateCheckbox ("Message 3" ,190, 230)
Local $CheckMessage4 = GUICtrlCreateCheckbox ("Message 4" ,280, 230)
Local $CheckMessage5 = GUICtrlCreateCheckbox ("Message 5" ,370, 230)

Local $Liste = GUICtrlCreateCombo("Message 1", 10, 10, 185, 20)
Local $comboTEST = GUICtrlCreateCombo("Test", 250, 10, 200, 20)

GUICtrlSetData(-1, "Energy Star|myNoSleep")


GUISetState(@SW_SHOW)
GUICtrlSetData($Liste, "Message 2|Message 3|Message 4|Message 5")

;~ GUICreate/=================================================

$Read= IniRead ($SettingsFile, 'Message', 'Message1', "ERROR")
GUICtrlSetData ( $Input1, $Read )

Global $NombreBoucle = $Setting9

While (1)
   hGui ()
WEnd


Func hGui ()
      While 1
         $fRun1 = False
         $fRun2 = False
          Sleep(10)
               Switch GUIGetMsg()
                  Case $GUI_EVENT_CLOSE
                     Exit
                  Case $Liste ; Combot liste
                     $sComboRead = GUICtrlRead($Liste)
                     MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI)
                     If $sComboRead = "Message 1" Then
                        $Read= IniRead ($SettingsFile, 'Message', 'Message1', "ERROR")
                     ElseIf $sComboRead = "Message 2" Then
                        $Read= IniRead ($SettingsFile, 'Message', 'Message2', "ERROR")
                     ElseIf $sComboRead = "Message 3" Then
                        $Read= IniRead ($SettingsFile, 'Message', 'Message3', "ERROR")
                     ElseIf $sComboRead = "Message 4" Then
                        $Read= IniRead ($SettingsFile, 'Message', 'Message4', "ERROR")
                     ElseIf $sComboRead = "Message 5" Then
                        $Read= IniRead ($SettingsFile, 'Message', 'Message5', "ERROR")
                     EndIf

                     GUICtrlSetData ( $Input1, $Read )
                  Case $Boutton1 ; Selection nombre message
                        While (1)
                     If _IsChecked($CheckMessage1) Then
                        MsgBox($MB_SYSTEMMODAL, "Check", "The test Checkbox 1 is fine.", 10)
                     EndIf

                     If _IsChecked($CheckMessage2) Then
                        MsgBox($MB_SYSTEMMODAL, "Check", "The test Checkbox 2 is fine.", 10)
                     EndIf

                     If _IsChecked($CheckMessage3) Then
                        MsgBox($MB_SYSTEMMODAL, "Check", "The test Checkbox 3 is fine.", 10)
                     EndIf

                     If _IsChecked($CheckMessage4) Then
                        MsgBox($MB_SYSTEMMODAL, "Check", "The test Checkbox 4 is fine.", 10)
                     EndIf

                     If _IsChecked($CheckMessage5) Then
                        MsgBox($MB_SYSTEMMODAL, "Check", "The test Checkbox 5 is fine.", 10)
                     EndIf
                     ExitLoop
                        WEnd
                  Case $Boutton2 ; Enregistré message
                        $tempTexte = GUICtrlRead ($Input1)
                        $TempCombo = GUICtrlRead ($Liste)
                        If $TempCombo = "Message 1" Then
                           IniWrite ($SettingsFile, 'Message', 'Message1', $tempTexte)
                           MsgBox($MB_SYSTEMMODAL, "Check", "The test Whrite Message 1 runned fine.", 10)
                        EndIf

                        If $TempCombo = "Message 2" Then
                           IniWrite ($SettingsFile, 'Message', 'Message2', $tempTexte)
                           MsgBox($MB_SYSTEMMODAL, "Check", "The test Whrite Message 2 runned fine.", 10)
                        EndIf

                        If $TempCombo = "Message 3" Then
                           IniWrite ($SettingsFile, 'Message', 'Message3', $tempTexte)
                           MsgBox($MB_SYSTEMMODAL, "Check", "The test Whrite Message 3 runned fine.", 10)
                        EndIf

                        If $TempCombo = "Message 4" Then
                           IniWrite ($SettingsFile, 'Message', 'Message4', $tempTexte)
                           MsgBox($MB_SYSTEMMODAL, "Check", "The test Whrite Message 4 runned fine.", 10)
                        EndIf

                        If $TempCombo = "Message 5" Then
                           IniWrite ($SettingsFile, 'Message', 'Message5', $tempTexte)
                           MsgBox($MB_SYSTEMMODAL, "Check", "The test Whrite Message 5 runned fine.", 10)
                        EndIf


                  Case $Boutton3 ; Start
                     $SwitchBoutton = GUICtrlRead ($Boutton3)
                        If $SwitchBoutton = "Start" Then
                     _RunBoucle1 ()
                        ElseIf $SwitchBoutton = "Stop" Then
                     _RunBoucle2 ()
                        EndIf

                  Case $comboTEST ;test
                     $sCurrCombo = ""
                     If GUICtrlRead($comboTEST) <> $sCurrCombo Then
                        $sCurrCombo = GUICtrlRead($comboTEST)
                        MsgBox(0, "Choice", $sCurrCombo)
                     EndIf

               EndSwitch
      WEnd
EndFunc

Func _RunBoucle1 ()
   _Boucle1 ()
EndFunc

Func _Boucle1()
                        $SwitchBoutton = GUICtrlRead ($Boutton3)
                        $TempsInput = GUICtrlRead ($Input2)
                        MsgBox($MB_SYSTEMMODAL, "Check", "The test "&$TempsInput&" is fine.", 10)
                        If $SwitchBoutton = "Start" Then
                           GUICtrlSetData ($Boutton3,"Stop")
                           MsgBox($MB_SYSTEMMODAL, "Check", "The test StartPressedStopEdited is fine.", 10)
;                             Do
;                                Switch GUIGetMsg()
;                                   Case $Boutton3
;                                      ExitLoop
;                             EndSwitch
;                                   $NombreBoucle = $NombreBoucle -1
;                                   GUICtrlSetData ($Input3, $NombreBoucle)
;                                   $TempsInput = GUICtrlRead ($Input2)
;                                   Sleep($TempsInput)
;                                      If _IsChecked ($CheckMessage1) Then
;                                         Send ($Setting3)
;                                      ElseIf _IsChecked ($CheckMessage1) Then
;                                         Send ($Setting4)
;                                      ElseIf _IsChecked ($CheckMessage1) Then
;                                         Send ($Setting5)
;                                      ElseIf _IsChecked ($CheckMessage1) Then
;                                         Send ($Setting6)
;                                      ElseIf _IsChecked ($CheckMessage1) Then
;                                         Send ($Setting7)
;                                      EndIf
;
;                          Until $NombreBoucle = 0 Or _IsPressed ("72",$hDLL)
                        EndIf
EndFunc

Func _RunBoucle2 ()
   _Boucle2 ()
EndFunc

Func _Boucle2()
                        $SwitchBoutton = GUICtrlRead ($Boutton3)
                        $TempsInput = GUICtrlRead ($Input2)
                        MsgBox($MB_SYSTEMMODAL, "Check", "The test "&$TempsInput&" is fine.", 10)
                        If $SwitchBoutton = "Stop" Then
                           GUICtrlSetData ($Boutton3,"Start")
                           MsgBox($MB_SYSTEMMODAL, "Check", "The test StopPressedStartEdited is fine.", 10)
                        EndIf
EndFunc

Func Spam()
   Sleep(1000)

EndFunc


Func Exite ()
    Exit
EndFunc

Func Pause()
    $Paused = NOT $Paused
While  $Paused
        Sleep (500)
WEnd
EndFunc; => Pause()

Func _IsChecked($idControlID) ;==>Detection d'une box checker
   Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi.

see the help file for

GUICtrlCreateButton

 there you can see how to handle your problem using different buttons for "start" and "stop" by doing a while loop, that's "watching button operations".

 

#include <GUIConstantsEx.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Create a button control.
    Local $idNotepad = GUICtrlCreateButton("Run Notepad", 120, 170, 85, 25)
    Local $idClose = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $iPID = 0

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idClose
                ExitLoop

            Case $idNotepad
                ; Run Notepad with the window maximized.
                $iPID = Run("notepad.exe", "", @SW_SHOWMAXIMIZED)

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)

    ; Close the Notepad process using the PID returned by Run.
    If $iPID Then ProcessClose($iPID)
EndFunc   ;==>Example

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

I want to use Only one boutton. The purpose is also to improving my skill.

 

And not only to get that working. 

 

Share this post


Link to post
Share on other sites

caramen,

When you asked via PM if you could post a thread about interrupting a loop I did not expect you to repost essentially the same code as in the thread I locked yesterday. What are you thinking? If the code was unacceptable yesterday, it remains unacceptable today.

If you want to learn how to interrupt a function than post some code which is not going to cause me to interrupt what I was doing to come and close this thread too. And if I see this code again you will get a short holiday.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.