AntiFros Posted June 24, 2014 Share Posted June 24, 2014 Click start and it starts counting. When you click stop then it reacts and disable/enable buttons. But I dont know how to exit that loop or even whole func. Code: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> global $fInterrupt = 0 $Form1 = GUICreate("Form1", 374, 184, 192, 124) $start = GUICtrlCreateButton("start", 32, 32, 161, 49) $stop = GUICtrlCreateButton("stop", 32, 96, 161, 49) $Label1 = GUICtrlCreateLabel("Label1", 216, 72, 92, 17) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $start GUICtrlSetState($start, $GUI_DISABLE) GUICtrlSetState($Stop, $GUI_ENABLE) core() EndSwitch WEnd Func core() AdlibRegister("_Interrupt",2000) Local $i = 0 While 1 $i = $i + 1 Sleep(1000) GUICtrlSetData($Label1,$i) Wend Endfunc Func _Interrupt() If $fInterrupt Then Switch $fInterrupt Case 1 GUICtrlSetState($start, $GUI_ENABLE) GUICtrlSetState($Stop, $GUI_DISABLE) $fInterrupt = 0 Return True Case 2 Exit EndSwitch EndIf Return False EndFunc ;==>_Interrupt Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $Stop Then $fInterrupt = 1 Return $GUI_RUNDEFMSG EndFunc Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) ; Closure [X} pressed If BitAND($wParam, 0xFFF0) = 0xF060 Then $fInterrupt = 2 EndIf Return $GUI_RUNDEFMSG EndFunc Link to comment Share on other sites More sharing options...
jdelaney Posted June 24, 2014 Share Posted June 24, 2014 Not the most elegant, but works: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> global $fInterrupt = 0 $Form1 = GUICreate("Form1", 374, 184, 192, 124) $start = GUICtrlCreateButton("start", 32, 32, 161, 49) $stop = GUICtrlCreateButton("stop", 32, 96, 161, 49) $Label1 = GUICtrlCreateLabel("Label1", 216, 72, 92, 17) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $start GUICtrlSetState($start, $GUI_DISABLE) GUICtrlSetState($stop, $GUI_ENABLE) core() EndSwitch WEnd Func core() AdlibRegister("_Interrupt", 100) Local $i = 0 While 1 If ControlCommand($Form1, "", $start, "IsEnabled") Then Return $i = $i + 1 Sleep(1000) GUICtrlSetData($Label1, $i) Wend Endfunc ;==>core Func _Interrupt() If $fInterrupt Then Switch $fInterrupt Case 1 GUICtrlSetState($start, $GUI_ENABLE) GUICtrlSetState($stop, $GUI_DISABLE) $fInterrupt = 0 Return True Case 2 Exit EndSwitch EndIf Return False EndFunc ;==>_Interrupt Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $stop Then $fInterrupt = 1 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) ; Closure [X} pressed If BitAND($wParam, 0xFFF0) = 0xF060 Then $fInterrupt = 2 EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_SYSCOMMAND IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
Gianni Posted June 24, 2014 Share Posted June 24, 2014 (edited) p.s if you are interested to stopwatches this 2 links could also interest you >simple stopwatch udf >Stopwatch UDF - Based on the concept in .NET Edited June 24, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
AntiFros Posted June 24, 2014 Author Share Posted June 24, 2014 Sorry, forgot to mention that I want to stop lopp/ exit func without writing code into it. If writing code into it then best way is to put if _Interrupt then exitloop The problem is that I have too much code which I need to stop. I need to put in like 50 lines "if _Interrupt then exitloop". I want to do it easer. Link to comment Share on other sites More sharing options...
AntiFros Posted June 24, 2014 Author Share Posted June 24, 2014 (edited) I think this worked. Making While $loop = 1 instead of While 1 and when button clicked then it makes $loop = 0. So it stops. This is good way to do that? expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> global $fInterrupt = 0, $loop = 1 $Form1 = GUICreate("Form1", 374, 184, 192, 124) $start = GUICtrlCreateButton("start", 32, 32, 161, 49) $stop = GUICtrlCreateButton("stop", 32, 96, 161, 49) $Label1 = GUICtrlCreateLabel("Label1", 216, 72, 92, 17) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $start GUICtrlSetState($start, $GUI_DISABLE) GUICtrlSetState($Stop, $GUI_ENABLE) core() EndSwitch WEnd Func core() AdlibRegister("_Interrupt",2000) Local $i = 0 While $loop = 1 $i = $i + 1 Sleep(1000) GUICtrlSetData($Label1,$i) Wend Endfunc Func _Interrupt() If $fInterrupt Then Switch $fInterrupt Case 1 GUICtrlSetState($start, $GUI_ENABLE) GUICtrlSetState($Stop, $GUI_DISABLE) $loop = 0 $fInterrupt = 0 Return True Case 2 Exit EndSwitch EndIf Return False EndFunc ;==>_Interrupt Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $Stop Then $fInterrupt = 1 Return $GUI_RUNDEFMSG EndFunc Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) ; Closure [X} pressed If BitAND($wParam, 0xFFF0) = 0xF060 Then $fInterrupt = 2 EndIf Return $GUI_RUNDEFMSG EndFunc Edited June 24, 2014 by AntiFros Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 24, 2014 Moderators Share Posted June 24, 2014 AntoFros,Why so complicated? For something this simple just keep the code simple too: #include <GUIConstantsEx.au3> Global $fRun = False $Form1 = GUICreate("Form1", 374, 184, 192, 124) $start = GUICtrlCreateButton("start", 32, 32, 161, 49) $stop = GUICtrlCreateButton("stop", 32, 96, 161, 49) GUICtrlSetState($stop, $GUI_DISABLE) $Label1 = GUICtrlCreateLabel("0", 216, 72, 92, 17) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $start GUICtrlSetState($start, $GUI_DISABLE) GUICtrlSetState($stop, $GUI_ENABLE) $nBegin = TimerInit() $fRun = True Case $stop GUICtrlSetState($start, $GUI_ENABLE) GUICtrlSetState($stop, $GUI_DISABLE) $fRun = False EndSwitch If $fRun And TimerDiff($nBegin) > 1000 Then GUICtrlSetData($Label1, GUICtrlRead($Label1) + 1) $nBegin = TimerInit() EndIf WEndAll 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...
AntiFros Posted June 24, 2014 Author Share Posted June 24, 2014 (edited) Ahh can't explain with my bad english. Timer in my code is just easy way to see if loop still works or not. The last code I posted works but loop stops after it finished everything what is in it. I need to put something here Func _Interrupt() If $fInterrupt Then Switch $fInterrupt Case 1 GUICtrlSetState($start, $GUI_ENABLE) GUICtrlSetState($stop, $GUI_DISABLE) HERE///////////////////////////////////////////////////////////// $fInterrupt = 0 Return True Case 2 Exit EndSwitch EndIf Return False EndFunc ;==>_Interrupt Code which would end loop in core() or stop whole core() func. Edited June 24, 2014 by AntiFros Link to comment Share on other sites More sharing options...
Gianni Posted June 24, 2014 Share Posted June 24, 2014 (edited) are you trying to exit from the while - wend loop within the core() function by an "external" event? Edited June 24, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 24, 2014 Moderators Share Posted June 24, 2014 AntiFros,How about this script then: expandcollapse popup#include <StaticConstants.au3> #include <WindowsConstants.au3> Global $fInterrupt = 0 $Form1 = GUICreate("Form1", 374, 184, 192, 124) $start = GUICtrlCreateButton("start", 32, 32, 161, 49) $stop = GUICtrlCreateButton("stop", 32, 96, 161, 49) GUICtrlSetState($stop, $GUI_DISABLE) $Label1 = GUICtrlCreateLabel("Label1", 216, 72, 92, 17) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $start GUICtrlSetState($start, $GUI_DISABLE) GUICtrlSetState($stop, $GUI_ENABLE) core() EndSwitch WEnd Func core() Local $i = 1, $nBegin = TimerInit() While 1 If TimerDiff($nBegin) > 1000 Then $i = $i + 1 GUICtrlSetData($Label1, $i) $nBegin = TimerInit() EndIf If $fInterrupt Then Switch $fInterrupt Case 1 $fInterrupt = False GUICtrlSetState($start, $GUI_ENABLE) GUICtrlSetState($stop, $GUI_DISABLE) Return Case 2 Exit EndSwitch EndIf Sleep(10) WEnd EndFunc ;==>core Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $stop Then $fInterrupt = 1 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) ; Closure [X} pressed If BitAND($wParam, 0xFFF0) = 0xF060 Then $fInterrupt = 2 EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_SYSCOMMANDAny better? 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...
AntiFros Posted June 24, 2014 Author Share Posted June 24, 2014 (edited) are you trying to exit from the while - wend loop within the core() function by an "external" event? Im trying to exit whole func. If I stop loop then func ends and it stops. So also I can directly exitfunc. Didnt understood half of your sentence but yes, Im trying to exit func outside it. Without any code in core() func. Melba, nope. Ill probably just put "If _Interrupt() then exitloop" in every second line. If there would be func like ExitFunc(core)... Edited June 24, 2014 by AntiFros Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 24, 2014 Moderators Share Posted June 24, 2014 AntiFros,In your original script, the core function had a loop - which is why I used one. If there is no loop then you are poorly placed to interrupt the function. Can you give us an idea of its internal structure - perhaps we might be able to suggest something. 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...
mLipok Posted June 24, 2014 Share Posted June 24, 2014 Ahh can't explain with my bad english. Timer in my code is just easy way to see if loop still works or not. The last code I posted works but loop stops after it finished everything what is in it. I need to put something here Func _Interrupt() If $fInterrupt Then Switch $fInterrupt Case 1 GUICtrlSetState($start, $GUI_ENABLE) GUICtrlSetState($stop, $GUI_DISABLE) HERE///////////////////////////////////////////////////////////// $fInterrupt = 0 Return True Case 2 Exit EndSwitch EndIf Return False EndFunc ;==>_Interrupt Code which would end loop in core() or stop whole core() func. Please use code tags when you post your code. Read "How to post code on the forum" from my singature. mLipok Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24 Link to comment Share on other sites More sharing options...
JohnOne Posted June 24, 2014 Share Posted June 24, 2014 Is this anything like the functionality you desire? HotKeySet("{ESC}", "_HotFunc") _Main() Func _Main() ConsoleWrite("_Main()" & @LF) While 3 _func1() Sleep(2000) WEnd EndFunc Func _func1() ConsoleWrite("_func1()" & @LF) _func2() EndFunc Func _func2() ConsoleWrite("_func2()" & @LF) EndFunc Func _HotFunc() _Main() EndFunc Recursion is not always bad when used wisely, but I'd not advice it in a tight loop or if it's something which will be used very often in your script. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
AntiFros Posted June 24, 2014 Author Share Posted June 24, 2014 (edited) Ok, shortened my main code to show what Im doing here. Im collecting data about player (talking about game called Battlefield 2. This is NOT a game automation). This code are showing me if player is online, if he got any score and so on. Just faster way to see what I can see also from surfing web. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <IE.au3> #include <array.au3> global $fInterrupt = 0 $oIE = _IECreate("http://37.187.75.29/bf2sclone/") $Form1 = GUICreate("Form1", 374, 184, 192, 124) $start = GUICtrlCreateButton("start", 32, 32, 161, 49) $stop = GUICtrlCreateButton("stop", 32, 96, 161, 49) $Label1 = GUICtrlCreateLabel("Label1", 216, 72, 92, 17) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $start GUICtrlSetState($start, $GUI_DISABLE) GUICtrlSetState($Stop, $GUI_ENABLE) core() EndSwitch WEnd Func core() _IELinkClickByText($oIE,"Scarred1.50") Sleep(3000) Local $oTable = _IETableGetCollection($oIE,0) Local $aTableData = _IETableWriteToArray($oTable) ;_ArrayDisplay($aTableData) While 1 ; there code refreshes page every 1-5 mins (random) ;and gathers information. ;So if you quit loop then func ends. ;there is about hundret lines of code mainly gathering tables, sleeps and _ielinkclicks. So I need easy way to stop it by pressing button. Wend Endfunc Func _Interrupt() If $fInterrupt Then Switch $fInterrupt Case 1 GUICtrlSetState($start, $GUI_ENABLE) GUICtrlSetState($Stop, $GUI_DISABLE) $fInterrupt = 0 Return True Case 2 Exit EndSwitch EndIf Return False EndFunc ;==>_Interrupt Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $Stop Then $fInterrupt = 1 Return $GUI_RUNDEFMSG EndFunc Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) ; Closure [X} pressed If BitAND($wParam, 0xFFF0) = 0xF060 Then $fInterrupt = 2 EndIf Return $GUI_RUNDEFMSG EndFunc Again, this is NOT game automation lol. ----Edit JohnOne, where is button? lol. Edited June 24, 2014 by AntiFros Link to comment Share on other sites More sharing options...
JohnOne Posted June 24, 2014 Share Posted June 24, 2014 Obviously there is no button, what I have shown is a quick example of what functionality you might need. It shows that it will leave any function and any loop anywhere in your script and return to it's main function. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
AntiFros Posted June 24, 2014 Author Share Posted June 24, 2014 Any way to do it without using hotkey? Link to comment Share on other sites More sharing options...
JohnOne Posted June 24, 2014 Share Posted June 24, 2014 Yes, call it from a button press. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Gianni Posted June 24, 2014 Share Posted June 24, 2014 (edited) another simple example: you should declare a global variable (as you already done) for example global $fInterrupt = 0 then close all the functions that you want interrupt from the "outside" in a loop like this: While Not $fInterrupt ; your code goes here WEnd so when you want to exit just set the $fInterrupt to true (in this example by a checkbox) expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $fInterrupt = 0, $loop = 1 AdlibRegister("_Interrupt", 500) ; check every half second if stop the loop(s) $Form1 = GUICreate("Form1", 374, 184, 192, 124) $start = GUICtrlCreateButton("start", 32, 32, 161, 49) ; $stop = GUICtrlCreateButton("stop", 32, 96, 161, 49) $Label1 = GUICtrlCreateLabel("Label1", 216, 72, 92, 17) Global $iCheckbox = GUICtrlCreateCheckbox("interrupt", 10, 10, 185, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $start GUICtrlSetState($start, $GUI_DISABLE) core() ; this starts the loop in the core() function GUICtrlSetState($start, $GUI_ENABLE) GUICtrlSetState($iCheckbox, $GUI_UNCHECKED) EndSwitch WEnd Func core() Local $i = 0 While Not $fInterrupt ; $i$loop = 1 $i = $i + 1 Sleep(1000) GUICtrlSetData($Label1, $i) WEnd EndFunc ;==>core Func _Interrupt() $fInterrupt = GUICtrlRead($iCheckbox) <> 4 EndFunc ;==>_Interrupt Edited June 24, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... 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