Ronald Posted July 9, 2012 Share Posted July 9, 2012 Lets say we had this code which lets button 2 interrupt button 1. What if I wanted when after clicking button 2, it stops 1 completely and button 1's function never resumes until I click it again. How would it be done? expandcollapse popup#include <GUIConstantsEx.au3> ; Declare a flag Global $fRunOne = False Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30) GUICtrlSetOnEvent($hButton_1, "_Func_1") $hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30) GUICtrlSetOnEvent($hButton_2, "_Func_2") GUISetState() While 1 Sleep(10) ; Check if the flag has been set by the OnEvent function If $fRunOne Then ; Now start the "real" function from within the main code _Func_1_Run() EndIf WEnd Func _Func_1() ; Set the flag within the OnEvent function $fRunOne = True EndFunc ;==>_Func_1 Func _Func_1_Run() For $i = 1 To 20 ConsoleWrite("-Func 1 Running" & @CRLF) Sleep(100) Next ConsoleWrite(">Func 1 Ended" & @CRLF) Global $fRunOne = False EndFunc ;==>_Func_1_Run Func _Func_2() For $i = 1 To 3 ConsoleWrite("+Func 2 Running" & @CRLF) Sleep(100) Next ConsoleWrite(">Func 2 Ended" & @CRLF) EndFunc ;==>_Func_2 Func _Exit() Exit EndFunc ;==>_Exit Link to comment Share on other sites More sharing options...
Ronald Posted July 9, 2012 Author Share Posted July 9, 2012 ah wait >.< didn't read thoroughly... lets see if the other method works Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 9, 2012 Moderators Share Posted July 9, 2012 Ronald, Welcome to the AutoIt forum. I would do it like this: expandcollapse popup#include <GUIConstantsEx.au3> ; Declare a flag Global $fRunOne = False Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30) GUICtrlSetOnEvent($hButton_1, "_Func_1") $hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30) GUICtrlSetOnEvent($hButton_2, "_Func_2") GUISetState() While 1 Sleep(10) ; Check if the flag has been set by the OnEvent function If $fRunOne Then ; Now start the "real" function from within the main code _Func_1_Run() EndIf WEnd Func _Func_1() ; Set the flag within the OnEvent function $fRunOne = True EndFunc ;==>_Func_1 Func _Func_1_Run() For $i = 1 To 20 ConsoleWrite("-Func 1 Running" & @CRLF) If $fRunOne = False Then ; Check if the flag is cleared <<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite(">Func 1 Ended Prematurely" & @CRLF) Return EndIf Sleep(100) Next ConsoleWrite(">Func 1 Ended" & @CRLF) Global $fRunOne = False EndFunc ;==>_Func_1_Run Func _Func_2() $fRunOne = False ; Clear the flag <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< For $i = 1 To 3 ConsoleWrite("+Func 2 Running" & @CRLF) Sleep(100) Next ConsoleWrite(">Func 2 Ended" & @CRLF) EndFunc ;==>_Func_2 Func _Exit() Exit EndFunc ;==>_Exit All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now