NassauSky Posted May 19, 2022 Share Posted May 19, 2022 (edited) Hi all, Can anyone help me and possibly explain why I'm getting the error message: Variable used without being declared.: on the following code AutoItSetOption ( "MustDeclareVars", 1) myFunction() Func myFunction($getCustomName=True) If $getCustomName Then MsgBox(0,"Custom Name",$getCustomName) Else MsgBox(0,"Custom Name","None Given") EndIf EndFunc Edited May 19, 2022 by NassauSky Typo Link to comment Share on other sites More sharing options...
TheXman Posted May 19, 2022 Share Posted May 19, 2022 2 minutes ago, NassauSky said: MsbBox(0,"Custom Name","None Given") MsbBox maybe? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
NassauSky Posted May 19, 2022 Author Share Posted May 19, 2022 (edited) Sorry that was just my typo. It was correct in my actual code. It specifically errors on : If $getCustomName Then If ^ ERROR Edited May 19, 2022 by NassauSky Link to comment Share on other sites More sharing options...
TheXman Posted May 19, 2022 Share Posted May 19, 2022 (edited) When I corrected MsbBox and reran the script, I didn't get any errors. The error I saw was on the MsbBox line. Edited May 19, 2022 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 19, 2022 Moderators Share Posted May 19, 2022 NassauSky, Works fine for me too. 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...
NassauSky Posted May 19, 2022 Author Share Posted May 19, 2022 Strange I'm going to have to see what else is going on. Thanks @TheXman & @Melba23 Link to comment Share on other sites More sharing options...
NassauSky Posted May 19, 2022 Author Share Posted May 19, 2022 Sorry OK I realized it must be my implementation: This example shows the error AutoItSetOption ( "MustDeclareVars", 1) Opt("GUIOnEventMode", 1) Global $hGUI = GUICreate("myHelper", 600, @DesktopHeight-80, @DesktopWidth-600, 0) ;w,h,x,y Global $hExportList = GUICtrlCreateButton("Export List",200,25,80,25) ;x,y,w,h GUICtrlSetOnEvent(-1, "myFunction") GUISetState() While 1 Sleep(10) WEnd Func myFunction($getCustomName=True); Handle both a button press in EventMode and a call to the function If $getCustomName Then MsgBox(0,"Custom Name","Called through button press") Else MsgBox(0,"Custom Name","Called through function call myFunction(False)") EndIf EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 19, 2022 Moderators Share Posted May 19, 2022 NassauSky, Here is how I might go about coding a solution: AutoItSetOption ( "MustDeclareVars", 1) Opt("GUIOnEventMode", 1) HotKeySet("{ESC}", "_Exit") Global $getCustomName = "Button" Global $hGUI = GUICreate("myHelper") Global $hExportList = GUICtrlCreateButton("Export List",200,25,80,25) ;x,y,w,h GUICtrlSetOnEvent(-1, "myFunction") GUISetState() myFunction_Direct("Direct") While 1 Sleep(10) WEnd Func myFunction_Direct($Param = True) $getCustomName = $Param myFunction() $getCustomName = "Button" EndFunc Func myFunction(); Handle both a button press in EventMode and a call to the function If $getCustomName = "Button" Then MsgBox(0,"Custom Name","Called through button press") Else MsgBox(0,"Custom Name","Called through function call with param: " & $getCustomName) EndIf EndFunc Func _Exit() Exit EndFunc M23 NassauSky 1 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...
NassauSky Posted May 19, 2022 Author Share Posted May 19, 2022 Thanks @Melba23. I try to use my Global Variables sparingly. That's what I'll wind up doing. It's just funny that the function does get called from the button event trigger and functions correctly if I don't make any references to the missing passed parameter. Link to comment Share on other sites More sharing options...
Subz Posted May 19, 2022 Share Posted May 19, 2022 (edited) Only occurs when using GuiOnEventMode and MustDeclareVars, you could use AutoItSetOption ( "MustDeclareVars", 1) Global $hGUI = GUICreate("myHelper", 600, @DesktopHeight-80, @DesktopWidth-600, 0) ;w,h,x,y Global $hExportList = GUICtrlCreateButton("Export List",200,25,80,25) ;x,y,w,h GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hExportList myFunction() EndSwitch WEnd Func myFunction($getCustomName = True); Handle both a button press in EventMode and a call to the function If $getCustomName Then MsgBox(0,"Custom Name","Called through button press") Else MsgBox(0,"Custom Name","Called through function call myFunction(False)") EndIf EndFunc Edited May 19, 2022 by Subz Link to comment Share on other sites More sharing options...
NassauSky Posted May 19, 2022 Author Share Posted May 19, 2022 (edited) Thanks @Subz Yeah in this case I created the app a year ago and was tweaking it and must have used EventMode for a reason. Was faster to implement the global variable option. Thanks again though I also like to hear other options like yours. Edited May 19, 2022 by NassauSky 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