Jump to content
Sign in to follow this  
Chobyhy

Using Global Varibles Within Functions

Recommended Posts

Chobyhy

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
Chobyhy

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
BAM5

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
Chobyhy

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
Antiec

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.