wonnylee Posted June 17, 2009 Share Posted June 17, 2009 My script is organized like this. Main function { GUI CREATED. button 1 -> run function A } A function { ........ ...... .......... } when i click button 1 in main function, A function is called and started with pop-up window.(including buttton 2 in pop-up window) And What i 'm wanting to do is like this.. if i click button 2 in pop-up window, i want to stop the A function. but A function script is quite long, so i cannot do it with while function. How can i stop the A function, while running A function?? and return to main function,,,, cf) A function is called by main function. i dunno where and how to put RETURN.. in A function.. plz help... thanks Link to comment Share on other sites More sharing options...
cageman Posted June 17, 2009 Share Posted June 17, 2009 if you want to functio to end just type return 0 for example or any other result. if you want to return $result for example: return $result that would exit the function immediatly Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 17, 2009 Moderators Share Posted June 17, 2009 (edited) wonnylee,You will have to poll GUIGetMsg() from within Function A to see if Button 2 has been pressed. If you have an existing While...WEnd (or similar) loop then it is easy to insert. If not, then you might want to think along the following lines:expandcollapse popup#include <GUIConstantsEx.au3> AdlibEnable("Function_C") Global $fFlag = False $hGUI = GUICreate("Test", 500, 500) $hButton_1 = GUICtrlCreateButton("Func A", 10, 10, 80, 30) $hButton_2 = GUICtrlCreateButton("Func B", 10, 50, 80, 30) $hLabel_1 = GUICtrlCreateLabel("", 100, 10, 150, 20) $hLabel_2 = GUICtrlCreateLabel($fFlag, 100, 50, 150, 20) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE AdlibDisable() Exit Case $hButton_1 Function_A() EndSwitch WEnd Func Function_A() GUICtrlSetData($hLabel_1, "Function A running") Local $begin = TimerInit() While TimerDiff($begin) < 20000 Sleep(200) If $fFlag Then Function_B() EndIf WEnd GUICtrlSetData($hLabel_1, "Function A ended") EndFunc Func Function_B() MsgBox(0, "", "Button 2 pressed!") Global $fFlag = False GUICtrlSetData($hLabel_2, $fFlag) EndFunc Func Function_C() Local $begin = TimerInit() While TimerDiff($begin) < 50 If GUIGetMsg() = $hButton_2 Then $fFlag = True GUICtrlSetData($hLabel_2, $fFlag) EndIf WEnd EndFuncThis not perfect, but does work.M23Edit: Sorry, I should have made clear that you do NOT need a While...WEnd loop within Function A. If you do not have a loop then you just need to test the $fFlag from time to time during Function A using:If GUIGetMsg() = $hButton_2 Then $fFlag = True GUICtrlSetData($hLabel_2, $fFlag) ; Here you need to decide whether to continue with Function A (do nothing) or go back to the main loop (Return) EndIf Edited June 17, 2009 by Melba23 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...
Inverted Posted June 17, 2009 Share Posted June 17, 2009 What about _Adlib.au3 ? (I have never used it, just found it and it looks awesome !)http://www.autoitscript.com/forum/index.php?showtopic=83967 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 17, 2009 Moderators Share Posted June 17, 2009 Inverted,That is exactly why I used Adlib in the example above! ;-)I agree it is very useful - and even more so in the new Beta.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...
Inverted Posted June 17, 2009 Share Posted June 17, 2009 Your solution uses the standard Adlib and requires a while loop. The OP noted that he'd rather avoid that. It seems _Adlib.au3 could be a better/easier/more robust solution. It even has pause/resume funcitonality ... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 17, 2009 Moderators Share Posted June 17, 2009 Inverted, Apologies, misread your post. 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...
wonnylee Posted June 18, 2009 Author Share Posted June 18, 2009 thanks for your help. I used AdlibEnable function with 3sec option, .. Main Func() GUICREATE, buttonCreate A -> Run Func A EndFunc Func A EnableAdlib("Stop", 3000) popup window(handle_popup) with button create button KKK -> If button is clicked, Function A should be terminated and return to main function GUI ........ ......... ................ ............. EndFunc Func Stop() $msg_3 = GUIGetmsg() Local $begin = TimerInit() While TimerDiff($begin) < 50 If GUIGetMsg() = $button_KKK Then GUISetState(@SW_HIDE, $handle_popup) Return 0 EndIf WEnd EndFunc but with this , even if i click button KKK several times(for longer than 3 sec), func A cannot be stopped. 'RETURN' doesn't work for function A, i think it only works in Stop function. I want terminate func A, while function A is running ,,, when i click button KKK.. plz help.. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 18, 2009 Moderators Share Posted June 18, 2009 wonnylee, As you have discovered it is not easy to break into a running function. Please post your "Function_A" so the internal structure can be seen - it might help. 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...
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