mr-es335 Posted December 26, 2024 Posted December 26, 2024 (edited) Good day, I hope that all is having a great day thus far? I hope, as always, that I am asking the appropriate questions here? I have the following script which provides the ability to launch and to exit notepad. However, the GUI "appears" sluggish! Here is the script: expandcollapse popup; ----------------------------------------------- #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- $Form1 = GUICreate("", 95, 45) $Button = GUICtrlCreateButton("Launch Me", 10, 10, 75, 25) GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button _LaunchTAC() _form2() EndSwitch WEnd ; ----------------------------------------------- Func _LaunchTAC() Local $sSrcAppPath = "C:\Windows\System32\notepad.exe" ; ----------------------------------------------- Run($sSrcAppPath) ; ----------------------------------------------- Sleep(500) ; ----------------- WinMove("[CLASS:Notepad]", "", 150, 250, 250, 250) EndFunc ;==>_LaunchTAC ; ----------------------------------------------- Func _form2() $Form2 = GUICreate("", 95, 45, 215, 340) $Button = GUICtrlCreateButton("Exit Me", 10, 10, 75, 25) ; ----------------- GUISetState(@SW_SHOW) ; ----------------- While 2 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button _ExitMe() GUIDelete($Form2) GUISetState(@SW_ENABLE, $Form1) Return EndSwitch WEnd EndFunc ;==>_form2 ; ----------------------------------------------- Func _ExitMe() Local $sAppTitle = "[CLASS:Notepad]" ; ----------------------------------------------- WinClose($sAppTitle) EndFunc ;==>_ExitTac ; ----------------------------------------------- Also, I am not able to execute the first button command a second time! Any ideas|suggestions would be greatly appreciated. Edited December 26, 2024 by mr-es335 lizaclarraa 1 mr-es335 Sentinel Music Studios
argumentum Posted December 27, 2024 Posted December 27, 2024 use #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 Don't call every button $Button. pixelsearch and lizaclarraa 2 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
sleepydvdr Posted December 27, 2024 Posted December 27, 2024 You can replace Sleep(500) With: WinWaitActive("[CLASS:Notepad]") And Local $sSrcAppPath = "C:\Windows\System32\notepad.exe" ; ----------------------------------------------- Run($sSrcAppPath) With simply: Run("notepad") And the same would go for WinClose("notepad") I'm not sure if these would speed up your script. The WinWaitActive would be better because some computers may take longer than 500ms and super fast computers won't need to wait that long. And the other suggestions just simplifies the code a little (and the script would work on computers where the OS is installed on a different partition than C:. Your script was not sluggish on my computer, btw. #include <ByteMe.au3>
pixelsearch Posted December 27, 2024 Posted December 27, 2024 (edited) 20 hours ago, mr-es335 said: Also, I am not able to execute the first button command a second time! @argumentum pointed out the main issue in the script : it's the $Button control created twice with the same variable name : 1) First time, outside a function, it is created as an implicit Global variable : all variables not created inside functions are Global, as explained in this wiki link By default, AutoIt scopes any variables declared in the main body of a script (that is not between a Func and EndFunc pair) as Global and any variables declared within function declarations as Local. But it is a good idea to explicitly declare your variables to make sure that you get what you want [...] If you use the AutoItSetOption("MustDeclareVars", 1) directive you must declare the scope of your variables or you will get error messages [...] AutoIt even allows you to use the same name for Global and Local variables, although this is not recommended as it could easily lead to confusion [...] The value of the $Button variable in main body is 3 (when it is first declared) 2) Second time, inside function _form2() , $Button is declared again (with a value of 4 this time) Because you used the same variable name, then you just changed the value of the Global variable $Button in main body from 3 to 4, as displayed in the Console when you add 2 ConsoleWrite lines to your script : ... $Form1 = GUICreate("", 95, 45) $Button = GUICtrlCreateButton("Launch Me", 10, 10, 75, 25) ConsoleWrite("In Main : $Button = " & $Button & @crlf) ; <============= added line (displays 3) GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE ConsoleWrite("In Main : $Button = " & $Button & @crlf) ; <============= added line (displays 4 if you called _form2() Exit ... That's why your $Button in Form1 is not active anymore after you called _form2() , it was created in main body with a value of 3, not 4, so it won't react when you press it again in Form1 Here is the console output, after you called _form2() , closed it then exited the script from Form1 : In Main : $Button = 3 In Main : $Button = 4 Edited December 27, 2024 by pixelsearch typo Musashi and mr-es335 1 1
mr-es335 Posted December 27, 2024 Author Posted December 27, 2024 Hello, Thanks for the "tips"! Appreciated! What is wrong with this? expandcollapse popup; ----------------------------------------------- #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; ----------------------------------------------- Global $Form1 Global $Form2 Global $ButtonF1a ; ----------------------------------------------- _Form1() ; ----------------------------------------------- Func _Form1() $Form1 = GUICreate("Form1", 145, 45) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- $ButtonF1a = GUICtrlCreateButton("Launch Me", 10, 10, 125, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonF1a GUICtrlSetState($ButtonF1a, $GUI_DISABLE) _LaunchNP() _Form2() EndSwitch WEnd EndFunc ;==>_Form1 ; ----------------------------------------------- Func _Form2() $Form2 = GUICreate("", 40, 35, 540, 280, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x505050) ; ----------------------------------------------- Local $ButtonF2 = GUICtrlCreateLabel("Exit", 5, 5, 40, 25) GUICtrlSetColor(-1, 0xFFFFFF) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonF2 _ExitNP() EndSwitch WEnd EndFunc ;==>_Form2 ; ----------------------------------------------- Func _LaunchNP() Local $sSrcAppPath = "C:\Windows\System32\notepad.exe" ; ----------------------------------------------- Run($sSrcAppPath) ; ----------------------------------------------- WinMove("[CLASS:Notepad]", "", 440, 170, 792, 590) EndFunc ;==>_LaunchNP ; ----------------------------------------------- Func _ExitNP() Local $sAppTitle = "[CLASS:Notepad]" ; ----------------------------------------------- WinClose($sAppTitle) GUIDelete($Form2) GUICtrlSetState($ButtonF1a, $GUI_ENABLE) EndFunc ;==>_ExitNP ; ----------------------------------------------- mr-es335 Sentinel Music Studios
pixelsearch Posted December 27, 2024 Posted December 27, 2024 (edited) Now you created a new issue in this 2nd script : deleting Form2() from _ExitNP() is not a good idea at all because you'll get stucked inside the While loop of Func _Form2() See what happens if we're displaying a counter in Func _Form2 Func _Form2() $Form2 = GUICreate("", 40, 35, 540, 280, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x505050) ; ----------------------------------------------- Local $ButtonF2 = GUICtrlCreateLabel("Exit", 5, 5, 40, 25) GUICtrlSetColor(-1, 0xFFFFFF) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- Local Static $iCounter = 0 While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonF2 _ExitNP() EndSwitch $iCounter += 1 ConsoleWrite($iCounter & @crlf) WEnd EndFunc ;==>_Form2 Notice what happens when Func _ExitNP() ends : the counter keeps on displaying in the Console, endlessly, indicating you're stucked in the While loop of Func _Form2 In your 1st script, the deletion of Form2 was done at the right place, followed by a Return which returned to Form1 In your 2nd script, the $GUI_EVENT_CLOSE event found inside the loop of Form2 is not executed automatically at the moment you delete Form2, so you don't exit the loop and you don't return to Form1 : even when you enable $ButtonF1a and press on it, it won't react. Edit1: $ButtonF1a doesn't react because $ButtonF1a is not a Case in the While loop of Func Form_2 Edit2: yes Edit1 is correct, just tested it after adding the following 2 silly lines in the While loop of Func Form_2 and it ConsoleWrite "HERE" when we press $ButtonF1a . These 2 lines are useful to debug, but they shouldn't be in the final script ! Case $ButtonF1a ConsoleWrite("HERE" & @crlf) Edited December 27, 2024 by pixelsearch
mr-es335 Posted December 27, 2024 Author Posted December 27, 2024 pixelseearch, My apologies, but I now more lost than ever!! Negating the first example, may i ask where to place the exit Form2 routine? mr-es335 Sentinel Music Studios
pixelsearch Posted December 27, 2024 Posted December 27, 2024 Just add a single line to your 2nd script : Case $ButtonF2 _ExitNP() ExitLoop mr-es335 1
mr-es335 Posted December 27, 2024 Author Posted December 27, 2024 pixelsearch, So, here is the completed scripts...all is now "appearing" to work as expected... expandcollapse popup#cs As Example3e, but employing notepad again. Status: Date: 12/28/24 #ce ; ----------------------------------------------- #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; ----------------------------------------------- Global $Form1 Global $Form2 Global $ButtonF1a ; ----------------------------------------------- _Form1() ; ----------------------------------------------- Func _Form1() $Form1 = GUICreate("Form1", 145, 45) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- $ButtonF1a = GUICtrlCreateButton("Launch Me", 10, 10, 125, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonF1a GUICtrlSetState($ButtonF1a, $GUI_DISABLE) _LaunchNP() _Form2() EndSwitch WEnd EndFunc ;==>_Form1 ; ----------------------------------------------- Func _Form2() $Form2 = GUICreate("", 40, 35, 640, 280, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") ;GUISetBkColor(0x505050) ; ----------------------------------------------- Local $ButtonF2 = GUICtrlCreateLabel("Exit", 5, 5, 25, 25, $SS_CENTER) ;GUICtrlSetColor(-1, 0xFFFFFF) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonF2 GUIDelete($Form2) _ExitNP() GUICtrlSetState($ButtonF1a, $GUI_ENABLE) ExitLoop EndSwitch WEnd EndFunc ;==>_Form2 ; ----------------------------------------------- Func _LaunchNP() Local $sSrcAppPath = "C:\Windows\System32\notepad.exe" ; ----------------------------------------------- Run($sSrcAppPath) ; ----------------------------------------------- WinMove("[CLASS:Notepad]", "", 535, 210, 792, 590) EndFunc ;==>_LaunchNP ; ----------------------------------------------- Func _ExitNP() Local $sAppTitle = "[CLASS:Notepad]" ; ----------------------------------------------- WinClose($sAppTitle) EndFunc ;==>_ExitNP ; ----------------------------------------------- Thanks again for ALL of your efforts and input!! pixelsearch 1 mr-es335 Sentinel Music Studios
pixelsearch Posted December 27, 2024 Posted December 27, 2024 (edited) You're welcome, glad that it worked If you don't mind, a few words concerning the variable $ButtonF1a 1) No need to make it Global : Global $ButtonF1a Local is enough : ; $ButtonF1a = GUICtrlCreateButton("Launch Me", 10, 10, 125, 25) Local $ButtonF1a = GUICtrlCreateButton("Launch Me", 10, 10, 125, 25) 2) Re-enable it at a place that gives a better readability of the script, by moving its enable line from Func _Form2() to Func _Form1() Case $ButtonF1a GUICtrlSetState($ButtonF1a, $GUI_DISABLE) _LaunchNP() _Form2() GUICtrlSetState($ButtonF1a, $GUI_ENABLE) By the way, what happened to the following useful line that you were using in all your scripts ? Opt("MustDeclareVars", 1) Edited December 27, 2024 by pixelsearch mr-es335 1
mr-es335 Posted December 27, 2024 Author Posted December 27, 2024 pixelsearch, Regarding your comments... [C]: Your comment [R]: My response C1: If you don't mind, a few words concerning the variable $ButtonF1a R1: Of course not.... C2: Re-enable it at a place that gives a better readability of the script, by moving its enable line from Func _Form2() to Func _Form1() R2: Makes perfect sense...[I only wish that I could see such at the time!!] Case $ButtonF1a GUICtrlSetState($ButtonF1a, $GUI_DISABLE) _LaunchNP() _Form2() GUICtrlSetState($ButtonF1a, $GUI_ENABLE) C3: By the way, what happened to the following useful line that you were using in all your scripts ? R3: Ooooopppsssss...!!!! Thanks again...!! mr-es335 Sentinel Music Studios
mr-es335 Posted December 28, 2024 Author Posted December 28, 2024 (edited) Hello, Is the following, "OK!"? expandcollapse popup#cs Filename: Example1b In this example, the "AddSoundFile" script will be adapted to the "Launch_TAC_Deployed_Version" script. Purpose: The "Launch_TAC_Deployed_Version" script employs the Switch|Case commands. Observations: It would appear that thus far, I am able to adapt the On_Event script to a Switch|Case script. Status: Ok! Date: 12/27/24 #ce ; ----------------------------------------------- #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $MainGui2 Global $sCol1Row1 Global $sColRow ; ----------------------------------------------- _MainGui1() ; ----------------------------------------------- Func _MainGui1() ConsoleWrite("_MainGui1()" & @CRLF) GUICreate("_MainGui1", 145, 75) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- $sCol1Row1 = GUICtrlCreateButton("AddSoundFile", 10, 10, 125, 25) Local $sCol1Row2 = GUICtrlCreateButton("Exit Me", 10, 40, 125, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $sCol1Row1 GUICtrlSetState($sCol1Row1, $GUI_DISABLE) _MainGui2() Case $sCol1Row2 _ExitMe() EndSwitch WEnd EndFunc ;==>_MainGui1 ; ----------------------------------------------- Func _MainGui2() ConsoleWrite("_MainGui2()" & @CRLF) $MainGui2 = GUICreate("", 115, 20, 115, 52, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x3D3D3D) ; ----------------------------------------------- $sColRow = GUICtrlCreateLabel("Enable HotKey", 0, 0, 115, 20, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $sColRow _EnableHotKey() EndSwitch WEnd EndFunc ;==>_MainGui2 ; ----------------------------------------------- Func _Close_MainGui2() ConsoleWrite("_Close_MainGui2()" & @CRLF) GUIDelete($MainGui2) _MainGui1() EndFunc ;==>Close_MainGui2 ; ----------------------------------------------- Func _EnableHotKey() ConsoleWrite("_EnableHotKey()" & @CRLF) Local Static $hbHotKeyEnabled = True ; ----------------------------------------------- If $hbHotKeyEnabled = True Then GUICtrlSetData($sColRow, "Exit") $hbHotKeyEnabled = False Else GUICtrlSetData($sColRow, "Enable HotKey") $hbHotKeyEnabled = True _Close_MainGui2() EndIf EndFunc ;==>_EnableHotKey ; ----------------------------------------------- Func _ExitMe() ConsoleWrite("_ExitMe()" & @CRLF) Exit EndFunc ;==>_ExitMe ; ----------------------------------------------- Edited December 28, 2024 by mr-es335 Updated example script mr-es335 Sentinel Music Studios
pixelsearch Posted December 28, 2024 Posted December 28, 2024 (edited) 1 hour ago, mr-es335 said: Is the following, "OK!"? No it is not, plenty of _MainGui1 windows will be opened at same time. I commented / added / modified some lines in your script : expandcollapse popup#cs In this example, the "AddSoundFile" script will be adapted to the "Launch_TAC_Deployed_Version" script. Purpose: The "Launch_TAC_Deployed_Version" script employs the Switch|Case commands. Observations: Status: Date: #ce ; ----------------------------------------------- #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $MainGui2 ; Global $sCol1Row1 ; no need Global $sColRow ; ----------------------------------------------- _MainGui1() ; ----------------------------------------------- Func _MainGui1() ConsoleWrite("_MainGui1()" & @CRLF) GUICreate("_MainGui1", 145, 75) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- Local $sCol1Row1 = GUICtrlCreateButton("AddSoundFile", 10, 10, 125, 25) ; added Local to this line Local $sCol1Row2 = GUICtrlCreateButton("Exit Me", 10, 40, 125, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $sCol1Row1 GUICtrlSetState($sCol1Row1, $GUI_DISABLE) _MainGui2() GUICtrlSetState($sCol1Row1, $GUI_ENABLE) ; added this line Case $sCol1Row2 _ExitMe() EndSwitch WEnd EndFunc ;==>_MainGui1 ; ----------------------------------------------- Func _MainGui2() ConsoleWrite("_MainGui2()" & @CRLF) $MainGui2 = GUICreate("", 115, 20, 115, 52, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x3D3D3D) ; ----------------------------------------------- $sColRow = GUICtrlCreateLabel("Enable HotKey", 0, 0, 115, 20, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $sColRow ; _EnableHotKey() ; this original line is not enough Local $bHotKeyStatus = _EnableHotKey() ; we need a return value ($bHotKeyStatus) to know how to continue If $bHotKeyStatus = True Then ExitLoop ; this will finally return to _MainGui1() loop EndSwitch WEnd EndFunc ;==>_MainGui2 ; ----------------------------------------------- Func _Close_MainGui2() ConsoleWrite("_Close_MainGui2()" & @CRLF) GUIDelete($MainGui2) ; _MainGui1() ; certainly not, you got to return to _MainGui1() one way or another, but not by calling it again from here ; or you'll get 2 _MainGui1 windows opened at same time, then 3, 4 etc... EndFunc ;==>Close_MainGui2 ; ----------------------------------------------- Func _EnableHotKey() ConsoleWrite("_EnableHotKey()" & @CRLF) Local Static $hbHotKeyEnabled = True ; ----------------------------------------------- If $hbHotKeyEnabled = True Then GUICtrlSetData($sColRow, "Exit") $hbHotKeyEnabled = False Else GUICtrlSetData($sColRow, "Enable HotKey") _Close_MainGui2() $hbHotKeyEnabled = True EndIf Return $hbHotKeyEnabled ; we return this value to the line that called _EnableHotKey() in _MainGui2() loop EndFunc ;==>_EnableHotKey ; ----------------------------------------------- Func _ExitMe() ConsoleWrite("_ExitMe()" & @CRLF) Exit EndFunc ;==>_ExitMe ; ----------------------------------------------- Edited December 28, 2024 by pixelsearch typo mr-es335 1
mr-es335 Posted December 28, 2024 Author Posted December 28, 2024 (edited) pixelsearch, Thanks for the "offering"...appreciated! • Note: The more I think I DO know, the more I discover how much I DO NOT know! • I am also adding filenames to my offerings...to ensure that I am sending the correct version...that was Example1b • I really meant to send the following...Example2a...is this a better rendering...barring information as provided in your latest offering? expandcollapse popup#cs Filename: Example2a The following is the original "Launch_TAC_Deployed_Version" - which employed a "_MainGui2()" function. As the "AddSoundFile" script already employs a "_MainGui2()" function, the "Launch_TAC_Deployed_Version" script will be updated to "_MainGui3()". Purpose: To update the original "Launch_TAC_Deployed_Version" script from "_MainGui2()" to "_MainGui3()". Observations: Status: Date: #ce ; ----------------------------------------------- #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- Global $MainGui2 ; ----------------------------------------------- _MainGui1() ; ----------------------------------------------- Func _MainGui1() ConsoleWrite("_MainGui1()" & @CRLF) GUICreate("_MainGui1", 145, 75) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- Local $sCol1Row1 = GUICtrlCreateButton("Launch TAC", 10, 10, 125, 25) Local $sCol1Row2 = GUICtrlCreateButton("Exit Me", 10, 40, 125, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $sCol1Row1 GUICtrlSetState($sCol1Row1, $GUI_DISABLE) _LaunchTAC() Sleep(600) _MainGui2() GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $sCol1Row2 _ExitMe() EndSwitch WEnd EndFunc ;==>_MainGui1 ; ----------------------------------------------- Func _MainGui2() ConsoleWrite("_MainGui2()" & @CRLF) GUICreate("", 40, 35, 640, 280, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x505050) ; ----------------------------------------------- Local $sColRow = GUICtrlCreateLabel("Exit", 5, 5, 25, 25, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $sColRow GUIDelete($MainGui2) _ExitTAC() ExitLoop EndSwitch WEnd EndFunc ;==>_MainGui2 ; ----------------------------------------------- Func _LaunchTAC() ConsoleWrite("_LaunchTAC()" & @CRLF) Local $sSrcAppPath = "D:\Install\System_Data\Apps\TAC\TAudioConverter.exe" ; ----------------------------------------------- Run($sSrcAppPath) ; ----------------------------------------------- WinMove("[CLASS:TAudioConverterUniqueName]", "", 535, 210, 792, 590) EndFunc ;==>_LaunchTAC ; ----------------------------------------------- Func _ExitTAC() ConsoleWrite("_ExitTAC()" & @CRLF) Local $sAppTitle = "[CLASS:TAudioConverterUniqueName]" ; ----------------------------------------------- WinClose($sAppTitle) EndFunc ;==>_ExitTAC ; ----------------------------------------------- Func _ExitMe() ConsoleWrite("_ExitMe()" & @CRLF) Exit EndFunc ;==>_ExitMe ; ----------------------------------------------- A question..."If Form1 calls Form2, and Form1 is then exited,..if Form2 then calls Form1 with Form2 being summarily exited, is there a need to 'return' information back to Form1?" PS: Maybe I should ask the question in this manner..."If one function is calling another function, should there always be a return value sent FROM the called function TO the calling function?" • See attached two examples... Example1.au3 Example2.au3 Edited December 28, 2024 by mr-es335 mr-es335 Sentinel Music Studios
pixelsearch Posted December 28, 2024 Posted December 28, 2024 Hello, 1) Concerning your Example2a (displayed in your last post) The script is ok, apart from the Global $MainGui2 which doesn't have a value in all the script, you probably forgot it here : ; GUICreate("", 40, 35, 640, 280, $WS_POPUP, $WS_EX_TOPMOST) $MainGui2 = GUICreate("", 40, 35, 640, 280, $WS_POPUP, $WS_EX_TOPMOST) And in the way the script is coded, you don't need it Global as the variable is only found in Func _MainGui2() so this should be enough : Local $MainGui2 = GUICreate("", 40, 35, 640, 280, $WS_POPUP, $WS_EX_TOPMOST) In this script, you're correctly ending Func _MainGui2() so the Return to Func _MainGui1() is correctly done. 2) Concerning your both attached scripts "Example1.au3" and "Example2.au3" They're both incorrect because you never end any function Func _Form1() or Func _Form2() The way you scripted them looks like this : _Form1() Func _Form1() _Form2() ConsoleWrite("Form1 : this line will never be displayed in Console") EndFunc ;==>_Form1 Func _Form2() _Form1() ConsoleWrite("Form2 : this line will never be displayed in Console") EndFunc ;==>_Form2 When you run this script, then you start a recursion process (calling functions from functions without ending any function) which will end abruptly at a certain time with this error message in the Console : ==> Recursion level has been exceeded - AutoIt will quit to prevent stack overflow. >Exit code: 1 mr-es335 1
pixelsearch Posted December 28, 2024 Posted December 28, 2024 (edited) I see you edited your last post to ask this : 3 hours ago, mr-es335 said: PS: Maybe I should ask the question in this manner..."If one function is calling another function, should there always be a return value sent FROM the called function TO the calling function?" In fact, in all the functions we create, there IS a default return value returned to the calling function. This value is 0 (except if you indicate by yourself that you want to return another value). For example, in this script... Local $iReturn1 = _Form1() ConsoleWrite("$iReturn1 = " & $iReturn1 & @crlf) ; displays False (0) Local $iReturn2 = _Form2() ConsoleWrite("$iReturn2 = " & $iReturn2 & @crlf) ; displays False (0) Func _Form1() ; whatever EndFunc ;==>_Form1 Func _Form2() ; whatever Return 0 ; or simply Return, that's equivalent EndFunc ;==>_Form1 ... 0 was returned from both functions, even from _Form1() which doesn't have a Return statement in it. So to answer your question, if you don't need to return a special value to the calling function, then a simple Return statement will be enough, but always have in mind that 0 will be returned in this case. Edited December 28, 2024 by pixelsearch mr-es335 1
mr-es335 Posted December 28, 2024 Author Posted December 28, 2024 (edited) pixelsearch, Regarding the above... Local $iReturn1 = _Form1() ConsoleWrite("$iReturn1 = " & $iReturn1 & @crlf) ; displays False (0) Local $iReturn2 = _Form2() ConsoleWrite("$iReturn2 = " & $iReturn2 & @crlf) ; displays False (0) Func _Form1() ; whatever EndFunc ;==>_Form1 Func _Form2() ; whatever Return 0 ; or simply Return, that's equivalent EndFunc ;==>_Form1 I can place either of the above [Local $iReturn1 = _Form1() or Local $iReturn2 = _Form2()] at a specific point in the script to verify|confirm the actual exit code? Is this correct? May I ask where precisely this text would be placed? • It would appear that such text is laced at the very beginning of the script! The HelpFile...at least to me, is rather vague regarding the "Return value method"...Would it be possible for an example how to test the return value of a function...and in particular, in my particular case? Thanks! For example, how do I get out of this? expandcollapse popup#cs Filename: Example2b2 -------------------------------------------- _MainGui2 is now updated! -------------------------------------------- Status: Date: 12/28/24 #ce ; ----------------------------------------------- #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; ----------------------------------------------- Opt("MustDeclareVars", 1) ; ----------------------------------------------- _MainGui1() ; ----------------------------------------------- Func _MainGui1() ;GUICreate("_MainGui1", 170, 75) Local $MainGui1 = GUICreate("_MainGui1", 170, 75) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- Local $sCol1Row1 = GUICtrlCreateButton("Launch Notepad", 10, 10, 150, 25) Local $sCol1Row2 = GUICtrlCreateButton("Exit Me", 10, 40, 150, 25) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $sCol1Row1 GUIDelete($MainGui1) ;GUICtrlSetState($sCol1Row1, $GUI_DISABLE) _LaunchNP() _MainGui2() ;GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $sCol1Row2 _ExitMe() EndSwitch WEnd EndFunc ;==>_MainGui1 ; ----------------------------------------------- Func _MainGui2() ;Local $MainGui2 = GUICreate("", 40, 35, 640, 280, $WS_POPUP, $WS_EX_TOPMOST) Local $MainGui2 = GUICreate("_MainGui2", 170, 45) GUISetFont(14, 800, 0, "Calibri") ;GUISetBkColor(0x505050) ; ----------------------------------------------- ;Local $sColRow = GUICtrlCreateLabel("Exit", 5, 5, 25, 25, $SS_CENTER) Local $sCol1Row1 = GUICtrlCreateButton("Exit Notepad", 10, 10, 150, 25) ;GUICtrlSetColor(-1, 0xFFFFFF) ; ----------------------------------------------- GUISetState(@SW_SHOW) ; ----------------------------------------------- While 1 Local $nMsg = GUIGetMsg() ; ----------------- Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $sCol1Row1 GUIDelete($MainGui2) _ExitNP() ExitLoop EndSwitch WEnd ConsoleWrite("Where am I now?" & @CRLF) ConsoleWrite("Just after _MainGui2 WEnd!" & @CRLF) EndFunc ;==>_MainGui2 ; ----------------------------------------------- Func _LaunchNP() Local $sSrcAppPath = "C:\Windows\System32\notepad.exe" ; ----------------------------------------------- Run($sSrcAppPath) ; ----------------------------------------------- Sleep(1) ; ----------------- ;WinMove("[CLASS:Notepad]", "", 600, 400, 250, 250) WinMove("[CLASS:Notepad]", "", 540, 200, 250, 250) EndFunc ;==>_LaunchNP ; ----------------------------------------------- Func _ExitNP() Local $sAppTitle = "[CLASS:Notepad]" ; ----------------------------------------------- WinClose($sAppTitle) EndFunc ;==>_ExitNP ; ----------------------------------------------- Func _ExitMe() Exit EndFunc ;==>_ExitMe ; ----------------------------------------------- Edited December 29, 2024 by mr-es335 mr-es335 Sentinel Music Studios
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