RagnaroktA Posted November 21, 2005 Share Posted November 21, 2005 Is there a way to exit out of/stop a currently running funciton (exit out of the loop, or something along those lines) I have a script, that retrieves computers on a domain, and I'd like to add a "Stop" feature for larger domains as a failsafe. What would be the best way? Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki Link to comment Share on other sites More sharing options...
SpookMeister Posted November 21, 2005 Share Posted November 21, 2005 (edited) You could set up the function so that it works on a conditional statement then set up another function that is called by a HotKey which turns on and off the conditional statement. Like so: HotKeySet("{F9}","StopFunction") $AllowFunction=0 ;Main program Func YourFunction() While $AllowFunction=0 ;Do your thing WEnd EndFunc Func StopFunction() If $AllowFunction=0 Then $AllowFunction=1 Else $AllowFunction=0 EndIf EndFunc This is assuming that your function is using a loop in the first place Edited November 21, 2005 by SpookMeister [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
RagnaroktA Posted November 21, 2005 Author Share Posted November 21, 2005 You could set up the function so that it works on a conditional statement then set up another function that is called by a HotKey which turns on and off the conditional statement. Like so: HotKeySet("{F9}","StopFunction") $AllowFunction=0 ;Main program Func YourFunction() While $AllowFunction=0 ;Do your thing WEnd EndFunc Func StopFunction() If $AllowFunction=0 Then $AllowFunction=1 Else $AllowFunction=0 EndIf EndFunc This is assuming that your function is using a loop in the first place The function uses For/Next... would this work the same way? Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki Link to comment Share on other sites More sharing options...
SpookMeister Posted November 21, 2005 Share Posted November 21, 2005 (edited) HotKeySet("{F9}","StopFunction") $AllowFunction=1 ;Main program Func YourFunction() For $x=1 to $y If $AllowFunction=1 Then ExitLoop EndIf ;Do your thing Next EndFunc Func StopFunction() If $AllowFunction=1 Then $AllowFunction=0 Else $AllowFunction=1 EndIf EndFunc Edited November 21, 2005 by SpookMeister [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] Link to comment Share on other sites More sharing options...
herewasplato Posted November 21, 2005 Share Posted November 21, 2005 (edited) ...exit out of/stop a currently running funciton (exit out of the loop...I assume that you mean without exiting the script???If you do not mind exiting the script, then just leave the icon in the system tray and kill it by clicking on that. You can include an "OnAutoItExit" function to close files or reset things as desired.If you want to exit a for/next loop and keep your script going, then use SpookMeister's code.Edit: You might want to put it all on one line and not have the EndIf - it is not neededIf $AllowFunction=1 Then ExitLoopThere is a slight speed advantage according to the help file..... Edited November 21, 2005 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
RagnaroktA Posted November 21, 2005 Author Share Posted November 21, 2005 I assume that you mean without exiting the script???If you do not mind exiting the script, then just leave the icon in the system tray and kill it by clicking on that. You can include an "OnAutoItExit" function to close files or reset things as desired.If you want to exit a for/next loop and keep your script going, then use SpookMeister's code.Edit: You might want to put it all on one line and not have the EndIf - it is not neededIf $AllowFunction=1 Then ExitLoopThere is a slight speed advantage according to the help file.....Right, stop the running function without exiting the script. The code seems solid, but when the stop button/hotkey/menu item is pressed (supposed to call the function) nothing happens. It's like the running function is voiding the action... Do I need to focus on the stop GUI items? Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki Link to comment Share on other sites More sharing options...
RagnaroktA Posted November 22, 2005 Author Share Posted November 22, 2005 *bump* Current Projects:Remote Administration Suite Updated! 12-20-07Remote User State Migration Tool (Plugin) Updated! 12-20-07Batch Print Wizard Updated! 12-20-07Links:AutoIt Beta | AutoIt Wiki Link to comment Share on other sites More sharing options...
herewasplato Posted November 22, 2005 Share Posted November 22, 2005 ...Do I need to focus on the stop GUI items?Make/post a small test script that demostrates your problem and maybe someone else can help you. I don't know much about GUIs... [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
SpookMeister Posted November 22, 2005 Share Posted November 22, 2005 (edited) I just noticed in my second example that the if condition is wrong. It should read... If $AllowFunction=0 Then Thats what I get for starting with reverse logic to begin with Edited November 22, 2005 by SpookMeister [u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote] 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