Bindlex Posted August 17, 2018 Share Posted August 17, 2018 Hello everyone, I have below an example script. When I click button "Start" a variable will increment infinite number of times. A second button "Exit", I want to use in order to close the script while the loop it's running, but it doesn't let me to do that, can exit only if I close from task manager. #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $total = 1 Global $number $Form1 = GUICreate("Form1", 246, 133, -1, -1) $Button1 = GUICtrlCreateButton("START", 8, 8, 177, 33) $Button2 = GUICtrlCreateButton("EXIT", 8, 48, 177, 33) $Label1 = GUICtrlCreateLabel("NUMBER : " & $number, 8, 96, 178, 17) GUISetState(@SW_SHOW, $Form1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 For $i = 0 To $total $i = 0 Sleep(100) $number += 1 GUICtrlSetData($Label1, "NUMBER : " & $number) Next Case $Button2 Exit EndSwitch WEnd Any idea how I can stop the script? Thank you! Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted August 17, 2018 Share Posted August 17, 2018 You could set up a button of your keyboard which, once pressed, stops the script Something like: While Not _IsPressed("SomeKey") ; Code WEnd Bindlex 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Developers Jos Posted August 17, 2018 Developers Share Posted August 17, 2018 Use the event mode for your buttons and logic like this: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ;0=disabled, 1=OnEvent mode enabled Global $total = 1 Global $number Global $Start=0 $Form1 = GUICreate("Form1", 246, 133, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $Button1 = GUICtrlCreateButton("START", 8, 8, 177, 33) GUICtrlSetOnEvent(-1,"_Start") $Button2 = GUICtrlCreateButton("EXIT", 8, 48, 177, 33) GUICtrlSetOnEvent(-1,"_Exit") $Label1 = GUICtrlCreateLabel("NUMBER : " & $number, 8, 96, 178, 17) GUISetState(@SW_SHOW, $Form1) While sleep(50) if $Start Then For $i = 0 To $total $i = 0 Sleep(100) $number += 1 GUICtrlSetData($Label1, "NUMBER : " & $number) Next EndIf WEnd Func _START() $Start=1 EndFunc Func _EXIT() Exit EndFunc Jos Bindlex 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted August 17, 2018 Developers Share Posted August 17, 2018 5 minutes ago, FrancescoDiMuro said: You could set up a button of your keyboard which, once pressed, stops the script Something like: While Not _IsPressed("SomeKey") ; Code WEnd This is not really using the Button to Stop/Exit and similar to using HotKeySet(). Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Bindlex Posted August 17, 2018 Author Share Posted August 17, 2018 Thank you, Jos. This is what I need. 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