ziongates Posted February 13, 2009 Share Posted February 13, 2009 I have a GUI APP with buttons and a couple of functions. I need to assign the "Cancel" button a command that interrupts the "CopyMaster" function below (or any other looping function). Basically: How do you kill a function or Several Functions via a button? Func CopyMaster($Dest_Path,$Source_Path) $Source = $Source_Path & "\*.*" If FileExists($Source) AND (DirGetSize ( $Source ) > 0 ) Then DirMove($Source,$_Dest_Path) EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 13, 2009 Moderators Share Posted February 13, 2009 ziongates,First thought is to use your "Cancel" button to set a global flag which you then check periodically within your functions. I do not believe there is any way of returning from a function other than by an internal decision of the function itself - although I am sure someone else knows a way and will tell us soon!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...
Authenticity Posted February 13, 2009 Share Posted February 13, 2009 You can use Opt('GuiOnEventMode', 1) and register an event for the Cancel button that will change a global variable but this will prevent your script from using a msg loop. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 13, 2009 Moderators Share Posted February 13, 2009 ziongates,I have played about a bit and have a solution. You need to use HotKeySet which was in fact my very first thought, but I then discarded it! Only this function will "break in" to set the flag - from the Help file: "A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes or is interrupted".So look at this:expandcollapse popup#include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Global $fCancel = False GUICreate("Test", 200,200) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Exit") GUICtrlCreateButton("GUI", 10, 10, 80, 30) GUICtrlSetOnEvent(-1, "On_GUI") GUICtrlCreateButton("Looper", 10, 85, 80, 30) GUICtrlSetOnEvent(-1, "On_Loop") Global $Label = GUICtrlCreateLabel("", 100, 85, 50, 30) HotKeySet("{SPACE}", "On_Cancel") Global $State = GUICtrlCreateLabel($fCancel, 10, 160, 50, 30) GUISetState() While 1 Sleep(100) WEnd Func On_Exit() Exit EndFunc Func On_Loop() $count = 0 While $count < 100 Sleep (1000) If $fCancel = True Then $fCancel = False GUICtrlSetData($State, $fCancel) GUICtrlSetData($Label, "") Return EndIf $count += 1 GUICtrlSetData($Label, $count) WEnd EndFunc Func On_GUI() $NewGUI = GUICreate("New GUI", 100, 100, 100, 100) GUISetState() Opt("GUIOnEventMode", 0) While 1 If GUIGetMsg() = -3 Then GUIDelete($NewGUI) Opt("GUIOnEventMode", 1) Return EndIf WEnd EndFunc Func On_Cancel() $fCancel = True GUICtrlSetData($State, $fCancel) EndFuncIf you press "Looper" the count begins and will not stop until you press the "HOT KEY" - the spacebar in this case.I hate to contradict Authenticity, but you can use both GUI modes in the same script - just not at the same time! If you press "GUI" you display a small window with its own GUIGetMsg loop - you have to reset the Opt("GUIOnEventMode") of course. However, once you are in this loop, the OnEvent "Looper" button does not work. The HotKey does though!I hope this is useful.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...
Manjish Posted February 13, 2009 Share Posted February 13, 2009 hey can't u like put the function in a Do..Until loop?? and put the condition of button pressed for the until expression?? I haven't tried this.. but can u do it?? [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
ziongates Posted February 13, 2009 Author Share Posted February 13, 2009 Thanks for all the responses, I'm investigating the "global variable check" option. 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