Jump to content

Recommended Posts

Posted

Hi,

My question is:

If I declare a variables in the main func, is it automatic set it as a global variables so I can use it

in the functions which called in the main func?

In the other function I must declare if the variables is global so I can use them in the main func?

Thanks

Posted

From the help file you could get that:

  Quote

The difference between Dim, Local and Global is the scope in which they are created:

Dim = Local scope if the variable name doesn't already exist globally (in which case it reuses the global variable!)

Global = Forces creation of the variable in the Global scope

Local = Forces creation of the variable in the Local/Function scope

You should use Local or Global, instead of Dim, to explicitly state which scope is desired for a variable/constant/array.

When using variables, the local scope is checked first and then the global scope second.

Note that your code will be very disorganized with global variables. Try sending them as parameters (Const or ByRef) and returning the result/results.

  • Moderators
Posted

atzoref,

You might find the Variables - using Global, Local and ByRef tutorial in the Wiki of interest. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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:

  Reveal hidden contents

 

Posted
  On 1/8/2012 at 8:58 AM, 'atzoref said:

If I declare a variables in the main func

AutoIt has no special main, or other name, function. There is Root level code and Function level code. ... Although using a function as a "main" start-up function is not a bad practice. ... The rest seems already covered.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

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
  • Recently Browsing   0 members

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