Jump to content

Global scope, Local scope? What's the difference?


Recommended Posts

I don't have much experience in software programming, so forgive me for this n00bish question.

I read the help topic about Dim/Local/Global/Const, and wondered, why use local over global, or global over local?

All it says in the help file is that they use the global/local scope. What's the point of using these?

No very good results turned up on Google, either, so I came here. :shocked:

Thanks,

SANDMAN!

[center]"Yes, [our app] runs on Windows as well as Linux, but if you had a Picasso painting, would you put it in the bathroom?" -BitchX.com (IRC client)"I would change the world, but they won't give me the source code." -Unknownsite . blog . portfolio . claimidcode.is.poetry();[/center]

Link to comment
Share on other sites

I don't have much experience in software programming, so forgive me for this n00bish question.

I read the help topic about Dim/Local/Global/Const, and wondered, why use local over global, or global over local?

All it says in the help file is that they use the global/local scope. What's the point of using these?

No very good results turned up on Google, either, so I came here. :shocked:

Thanks,

SANDMAN!

I't well explained in the help file but in general it's this:

Global works throughout your entire script

Local works ony withing the function where it is declared.

A String that is declared prior to a function will be Global in nature without the scope being declared

In a script as follows

$G = "String"

Global $G = "String"

Func MyFunc()

Local $G = "SomethingElse"

EndFunc

The first two $G declarations are both Global

The $G within the function is Local in nature and will only be used within that function. It also has no effect on the Global $G.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Yep I'm a n00b still working it out slowly..

From my experiences:

Global I find is great when you need a variable that can be set and called from any function or loop in your entire script.

Local is good if your using a variable within a function and your not using that variable outside of the function.

I don't think it's a case of one being better to use over the other,

I think it's more a case of what your needs are in your script at the time and the amount of system resources your script is permitted to chew.

My 2 cents ..lol

Cheers

Edit I'm too slow to answer once again.. doh

Edited by smashly
Link to comment
Share on other sites

Many people have requested File Local variables. These would be useful for UDFs that store information between calls. Global variables would work in the entire script, after it has been declared. Local variables work in their "scope" which is the area in which they were declared. File Local means it would only work in that file. Function Local only works in the function. If you declare a Local variable in a loop, I think it is also Loop Local.

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...