S1M1S Posted October 23, 2010 Posted October 23, 2010 (edited) I've encountered a snag where I call another function, but I can't get the original one to exit. For example: Func1() Func Func1() Func2() MsgBox ( 0, "", "Func1" ) EndFunc Func Func2() Func3() MsgBox ( 0, "", "Func2" ) EndFunc Func Func3() Func4() MsgBox ( 0, "", "Func3" ) EndFunc Func Func4() Func5() MsgBox ( 0, "", "Func4" ) EndFunc Func Func5() MsgBox ( 0, "", "Func5" ) EndFunc But what if I want to call Func2 AND close Func1? Is there some sort of function which does this: Func2() MsgBox ( 0, "", "Func1" ) EndFunc Func Func2() _Function_Close ( Func1 ) Func3() MsgBox ( 0, "", "Func2" ) EndFunc Any help would be greatly appreciated Edited October 23, 2010 by S1M1S
Moderators Melba23 Posted October 23, 2010 Moderators Posted October 23, 2010 S1M1S,Look at the Interrupting a running function tutorial in the Wiki - lots of information on how to it there. But it is a bit more complicated then a single line! 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
water Posted October 23, 2010 Posted October 23, 2010 @Melba23 Once again I'm impressed by the time and effort you've put into the wiki No one should be allowed to post a question on the forum before having read the wiki as a whole My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
BrewManNH Posted October 23, 2010 Posted October 23, 2010 The code below shows one way of doing it programmatically within your functions: Func1() Func Func1() $Return = Func2() If $Return > 0 Then Return MsgBox(0, "", "Func1") EndFunc ;==>Func1 Func Func2() $Return = Func3() If $Return > 0 Then Return MsgBox(0, "", "Func2") EndFunc ;==>Func2 Func Func3() $Return = Func4() If $Return > 0 Then Return MsgBox(0, "", "Func3") Return 1 ; <<<<<<<<<<<<<<<<<<<<<<< MsgBox in Func2 will not be run EndFunc ;==>Func3 Func Func4() $Return = Func5() If $Return > 0 Then Return MsgBox(0, "", "Func4") EndFunc ;==>Func4 Func Func5() MsgBox(0, "", "Func5") Return 1 ; <<<<<<<<<<<<<<<<<<<<<<< MsgBox in Func4 will not be run EndFunc ;==>Func5 You can use this method so that when you return from the previous function you will run whatever comes after the function call depending upon what happens in the called function. An If...Then statement for instance. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Moderators Melba23 Posted October 23, 2010 Moderators Posted October 23, 2010 BrewManNH, I feel your solution is the one the OP was looking for - I had not taken in that he was calling the new functions from within the running one. Note to self: Look at the code more closely! 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
S1M1S Posted October 26, 2010 Author Posted October 26, 2010 (edited) Hey, I took your advice Melba, don't worry - Though you do realize I had already been to that page... And thanks a ton BrewManNH - There's only one problem... I created this thread because I wanted to find out how it worked. Your example is great, and I will be able to mimic it whenever I need to - but how the heck does it work!? What does 'Return'ing 1 do? I know what return does, but returning 1!? Edited October 26, 2010 by S1M1S
Oneqa Posted October 26, 2010 Posted October 26, 2010 (edited) It doesn't matter what you value you return. What you will do with the return value does. Simply talking you use the return value to evaluate the successful execution of a function or even use the return value for another function execution or just display the value -EDIT- you could also use the Return command to exit a function and simply ignore the return value if you don't need it Edited October 26, 2010 by Oneqa
S1M1S Posted October 26, 2010 Author Posted October 26, 2010 (edited) I think I understand you... but why does the MsgBox not run? *EDIT: Ohhh! I get it now Thanks mate, much appreciated Edited October 26, 2010 by S1M1S
BrewManNH Posted October 26, 2010 Posted October 26, 2010 I think I understand you... but why does the MsgBox not run?When you jump to Func3 from Func2, the function call is assigned to a variable, in this case $Return. When Func3 ends, it sends the value of 1 back to the calling routine, and the $Return value is now equal to 1 because that is what I told Func3 to "Return" at the end of its execution. I could have set it to "Return" anything, in this case I set it to return the number 1. The line following the function call is an If...Then statement, that checks the variable $Return, and if its any value that is greater than 0, then it will Return to ITS calling function, rather than continuing the execution of the func2 function. That's why the MsgBox in Func2 won't run because it Returns to Func1 before its ever executed.I hope that doesn't confuse you too much, I'm horrible at explaining things. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Oneqa Posted October 26, 2010 Posted October 26, 2010 note that in func5 it return 1 which will result in skipping msgbox for the function that execute it which is func4. Func Func4() $Return = Func5() If $Return > 0 Then Return ;<=== This is true because func5 is returning 1, will immediately exit Func4 Func4 is returning empty string which is not greater than zero so msgbox will appear: Func Func3() $Return = Func4() If $Return > 0 Then Return ;<=== This is not true, will skip to next statement MsgBox(0, "", "Func3") ;<=== This is true because func5 is returning 1 As i said before when you issue return you will immediately exit the function and return the value after the "Return" statement.
S1M1S Posted October 26, 2010 Author Posted October 26, 2010 (edited) [Awesomeness] I hope that doesn't confuse you too much, I'm horrible at explaining things. It doesn't matter what you value you return. What you will do with the return value does. Simply talking you use the return value to evaluate the successful execution of a function or even use the return value for another function execution or just display the value -EDIT- you could also use the Return command to exit a function and simply ignore the return value if you don't need it Is there a 'like' button around here somewhere? [/Awesomeness] Edited October 26, 2010 by S1M1S
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