Jump to content

Using Global Varibles Within Functions


Chobyhy
 Share

Recommended Posts

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...