Sign in to follow this  
Followers 0
Chobyhy

Using Global Varibles Within Functions

7 posts in this topic

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.

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

What do you mean? The Variable is a GUI and I can't create that GUI until the function is called up.

Share this post


Link to post
Share on other sites

Any Help?

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0