DaProgrammer Posted August 28, 2007 Share Posted August 28, 2007 (edited) Func Func() For $i = 1 to 10 Sleep(1000) Next EndFunc This Function is running and does stuff to the gui, my question is how can i stop it when the user presses the stop button ? i tried the on event button to run something like $Exit = 1 but $Exit wont update till the running func will end Edited August 28, 2007 by DaProgrammer Link to comment Share on other sites More sharing options...
Generator Posted August 28, 2007 Share Posted August 28, 2007 AdilbEnable() Link to comment Share on other sites More sharing options...
DaProgrammer Posted August 28, 2007 Author Share Posted August 28, 2007 AdilbEnable() i though there might be a better way ill try implementing it and hopefully it will work or some1 will suggest something better. Link to comment Share on other sites More sharing options...
Developers Jos Posted August 28, 2007 Developers Share Posted August 28, 2007 post a snippet that has the Stop button to show what you are doing ... 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...
DaProgrammer Posted August 28, 2007 Author Share Posted August 28, 2007 post a snippet that has the Stop button to show what you are doing ... $Terminate = GUICtrlCreateButton("Exit",400,$WorkSpaceH+45,80,40) GUICtrlSetOnEvent($Terminate,"Terminate") Func Terminate() Exit EndFunc i tried to exit instead of stopping but it only exits when the loop is done Link to comment Share on other sites More sharing options...
DaProgrammer Posted August 28, 2007 Author Share Posted August 28, 2007 (edited) Adlib wont work since i cant read the button being pressed untill the func ends, so correct me if im wrong but its the same as a regular button EDIT : is there a way to check if the button was pressed in the last couple of seconds ? or leave the button in pressed position untill its read and raised ? Edited August 28, 2007 by DaProgrammer Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 28, 2007 Moderators Share Posted August 28, 2007 Adlib wont work since i cant read the button being pressed untill the func ends, so correct me if im wrong but its the same as a regular buttonYou're better off just using guigetmsg and doing away with onevent... put the guigetmsg in whatever loop you are currently in. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
DaProgrammer Posted August 28, 2007 Author Share Posted August 28, 2007 (edited) You're better off just using guigetmsg and doing away with onevent... put the guigetmsg in whatever loop you are currently in. can i use guigetmsg when in on event mode ? couse the prog does a lot of other stuff and im more comftable with on event EDIT : From the help File If the GUIOnEventMode option is set to 1 then the return from GUIGetMsg is always 0 and the @error is set to 1. Edited August 28, 2007 by DaProgrammer Link to comment Share on other sites More sharing options...
DaProgrammer Posted August 28, 2007 Author Share Posted August 28, 2007 Any more ideas ? there must be a way to terminate a loop with a button. BTW : the loop doesnt have to be a "FOR" it can be any loop but i hardly think it will make a diffrence. Link to comment Share on other sites More sharing options...
Developers Jos Posted August 28, 2007 Developers Share Posted August 28, 2007 $Terminate = GUICtrlCreateButton("Exit",400,$WorkSpaceH+45,80,40) GUICtrlSetOnEvent($Terminate,"Terminate") Func Terminate() Exit EndFunc i tried to exit instead of stopping but it only exits when the loop is doneI mean a snippet we can run and modify ... I am lazy and don't want to have to code before being able to test. 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...
DaProgrammer Posted August 28, 2007 Author Share Posted August 28, 2007 I mean a snippet we can run and modify ... I am lazy and don't want to have to code before being able to test. Opt("GUIOnEventMode",1) GuiCreate("MyGUI", 392, 323,-1, -1) $Button_1 = GuiCtrlCreateButton("Run", 210, 190, 100, 60) GUICtrlSetOnEvent($Button_1,"Count") $Button_2 = GuiCtrlCreateButton("Terminate", 50, 200, 110, 60) GUICtrlSetOnEvent($Button_2,"Terminate") $Label_3 = GuiCtrlCreateLabel("Label3", 130, 50, 100, 50) GuiSetState() While 1 Sleep(1000) WEnd Func Count() For $i = 1 to 10 GUICtrlSetData($Label_3,$i) Sleep(1000) Next EndFunc Func Terminate() Exit EndFunc if u press run it will count to 10 and if u press Terminate when it reaches 3 (just an example) it will w8 till 10 and then terminate Link to comment Share on other sites More sharing options...
Developers Jos Posted August 28, 2007 Developers Share Posted August 28, 2007 Opt("GUIOnEventMode",1) GuiCreate("MyGUI", 392, 323,-1, -1) $Button_1 = GuiCtrlCreateButton("Run", 210, 190, 100, 60) GUICtrlSetOnEvent($Button_1,"Count") $Button_2 = GuiCtrlCreateButton("Terminate", 50, 200, 110, 60) GUICtrlSetOnEvent($Button_2,"Terminate") $Label_3 = GuiCtrlCreateLabel("Label3", 130, 50, 100, 50) GuiSetState() While 1 Sleep(1000) WEnd Func Count() For $i = 1 to 10 GUICtrlSetData($Label_3,$i) Sleep(1000) Next EndFunc Func Terminate() Exit EndFunc if u press run it will count to 10 and if u press Terminate when it reaches 3 (just an example) it will w8 till 10 and then terminate Ok, see what you are doing now. Only one event is processed at a time so you need to return from an event Func as soon as possible to make the GUI respond again. 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...
DaProgrammer Posted August 28, 2007 Author Share Posted August 28, 2007 (edited) Ok, see what you are doing now. Only one event is processed at a time so you need to return from an event Func as soon as possible to make the GUI respond again. i know that exiting the function is the best way to check wheater to stop it or not.STROKE OF GENIUS : what if i enable adlib at 1000ms to change count, and button terminate will stop the adlib going to test it now.EDIT : it kinda works going to refine it and tell u how it came out Edited August 28, 2007 by DaProgrammer Link to comment Share on other sites More sharing options...
Mast3rpyr0 Posted August 28, 2007 Share Posted August 28, 2007 add a check in the for loop and use exitloop if it was pressed. My UDF's : _INetUpdateCheck() My Programs : GameLauncher vAlpha, InfoCrypt, WindowDesigner, ScreenCap, DailyRemindersPick3GeneratorBackupUtility! Other : Bored? Click Here! Link to comment Share on other sites More sharing options...
DaProgrammer Posted August 28, 2007 Author Share Posted August 28, 2007 i used a Function that makes one step and the Run button starts that function as and adlib, and the terminate button stops that adlib. So heres the solution for those intersted. 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