Chobyhy Posted December 9, 2007 Share Posted December 9, 2007 How can I declare a variable in a function and use the same variable in another function? For Example: Func One() Global $Label $Label = GUICtrlCreateLabel("Test", 10, 10) EndFunc Func Two() GuiCtrlDelete($Label) EndFunc Even though I declared it as Global, when I try to run it, it says Error, variable is being used before being declared. Link to comment Share on other sites More sharing options...
zfisherdrums Posted December 9, 2007 Share Posted December 9, 2007 Hello Chobyhy, Move the "Global $Label" declaration outside the function. This will make the $Label variable visible anywhere in the script. Zach... Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog... Link to comment Share on other sites More sharing options...
Chobyhy Posted December 9, 2007 Author Share Posted December 9, 2007 I already knew that, but its a GUI function so if it's outside, it won't work the way I want it to. This is OnEvent GUI mode. Link to comment Share on other sites More sharing options...
BAM5 Posted December 9, 2007 Share Posted December 9, 2007 How won't it work? If you have the variable pre-declared in the first line of your script then there will be no error. [center]JSON Encoding UDF[/center] Link to comment Share on other sites More sharing options...
Chobyhy Posted December 9, 2007 Author Share Posted December 9, 2007 What do you mean? The Variable is a GUI and I can't create that GUI until the function is called up. Link to comment Share on other sites More sharing options...
Chobyhy Posted December 10, 2007 Author Share Posted December 10, 2007 Any Help? Link to comment Share on other sites More sharing options...
Antiec Posted December 10, 2007 Share Posted December 10, 2007 It really should work with Global $Label Func One() $Label = GUICtrlCreateLabel("Test", 10, 10) EndFunc Func Two() GuiCtrlDelete($Label) EndFunc because first you allocate memory for the $label and then you just change it's value, which is a handle to the label. Have you even tried it? 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