mahsaad Posted February 27, 2013 Posted February 27, 2013 (edited) Hello all,I've read all the related topics, didn't find one to my question, so here it isConsider this scenario:;main au3 file Opt("GuiOnEventMode", 1) $main=GUICreate("Test", 200, 200) $ticket_gui_btn = GUICtrlCreateButton("Ticket GUI", 10, 10, 50, 30) GUICtrlSetOnEvent(-1, "ticket_gui") #include <ticket.au3> GUISetState(@SW_SHOW) While 1 Sleep(1000) ;Idle around WEnd func close_func() ;bla bla bla endFunc;another file: ticket.au3 Func ticket_gui() $child_gui = GUICreate("Test", 200, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "close_func") $ticket_input = GUICtrlCreateInput("", 10, 10, 140, 23) $send = GUICtrlCreateButton("Send", 10, 40 , 90, 25) GUICtrlSetOnEvent(-1, "verify_gui") GUISetState (@SW_SHOW, $child_gui) endFunc Func verify_gui() $ticket_value=GUICtrlRead($ticket_input, 1) if ticket_value="" then msgbox(0, "error", "Ticket is empty") endif endFuncIf i declare the $ticket_input as a global variables outside the 2 functions, the variable $ticket_input is visible in the verify_gui() function and it works fine of courseMy question: Is there an alternative instead of declaring it as a global variable?PS: i have to many child windows and variables. And functions (gui and the verification ones) must be separate as the example aboveThanks guysUpdateFor the ones who are suggestion using global variables, i'm already using that, i'm looking for an alternative solutionUsing a message loop won't work since i'm usingOpt("GuiOnEventMode", 1)If using global variables is the solution so be it, but i would like to read your opinion Edited February 27, 2013 by mahsaad
Nessie Posted February 27, 2013 Posted February 27, 2013 Something like this? $variable = "It's me mario!" _ShowMyVariable($variable) Func _ShowMyVariable($passed_variable) MsgBox(0,"","Your passed variable is: " & $passed_variable) EndFunc Hi! My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file
wakillon Posted February 27, 2013 Posted February 27, 2013 Use a Global variable : Global $Variable and you can use it in the entire script. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
mahsaad Posted February 27, 2013 Author Posted February 27, 2013 Something like this? $variable = "It's me mario!" _ShowMyVariable($variable) Func _ShowMyVariable($passed_variable) MsgBox(0,"","Your passed variable is: " & $passed_variable) EndFunc Hi! Thanks for the reply Your example the $variable = "It's me mario!" is outside a function, in that way it can be passed as a parameter in the function In my case the variable is in a function and i want to see it in a second function
Moderators Melba23 Posted February 27, 2013 Moderators Posted February 27, 2013 mahsaad,the variable is in a function and i want to see it in a second functionThen declare the variable in Global scope or code in MessageLoop mode and pass it as a parameter. 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
mahsaad Posted February 27, 2013 Author Posted February 27, 2013 Use a Global variable : Global $Variableand you can use it in the entire script.Thanks wakillon, i'm already using global variables, i was looking for an alternative solution
Nessie Posted February 27, 2013 Posted February 27, 2013 Thanks for the reply Your example the $variable = "It's me mario!" is outside a function, in that way it can be passed as a parameter in the function In my case the variable is in a function and i want to see it in a second function Like this?: _First_Function() Func _First_Function() $variable = "It's me mario!" _Second_Function($variable) EndFunc Func _Second_Function($passed_variable) MsgBox(0,"","Your passed variable is: " & $passed_variable) EndFunc My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file
mahsaad Posted February 27, 2013 Author Posted February 27, 2013 (edited) mahsaad, Then declare the variable in Global scope or code in MessageLoop mode and pass it as a parameter. M23 Thanks for the reply I'm using global variables already, i'm looking for an alternative solution I'm using Opt("GuiOnEventMode", 1) can't use message loop with that Edited February 27, 2013 by mahsaad
Nessie Posted February 27, 2013 Posted February 27, 2013 Look at my previous example My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file
Moderators Melba23 Posted February 27, 2013 Moderators Posted February 27, 2013 mahsaad,You have only those 2 choices: Global or MessageLoop. Your choice as to which you wish to use. Although martin did produce a UDF to enable parameter use in OnEvent if you want to try it. 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
mahsaad Posted February 27, 2013 Author Posted February 27, 2013 Like this?: _First_Function() Func _First_Function() $variable = "It's me mario!" _Second_Function($variable) EndFunc Func _Second_Function($passed_variable) MsgBox(0,"","Your passed variable is: " & $passed_variable) EndFunc Thanks again, That won't work either, the second function must be triggered when the button in the first function is pressed Thanks any way
mahsaad Posted February 27, 2013 Author Posted February 27, 2013 (edited) mahsaad, You have only those 2 choices: Global or MessageLoop. Your choice as to which you wish to use. Although martin did produce a UDF to enable parameter use in OnEvent if you want to try it. M23 Thanks for the reply I know about the udf, thanks for the suggestion, and i think those are the only solutions I already started with global variables so i guess i'll continue that way Plus the variables will be used in more than one function, in case i change the variable name, it will be easier to change it in one place instead of changing the parameters in all functions/files Edited February 27, 2013 by mahsaad
Moderators Melba23 Posted February 27, 2013 Moderators Posted February 27, 2013 mahsaad,i think those are the only solutionsSo my telling you exactly that twice already in this thread does not really convince you? 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
mahsaad Posted February 27, 2013 Author Posted February 27, 2013 (edited) mahsaad,So my telling you exactly that twice already in this thread does not really convince you? M23Of course it does Thank you Edited February 27, 2013 by mahsaad
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