themax90 Posted July 28, 2006 Posted July 28, 2006 (edited) As I sat down to talk with someone the other day it occured to me by the questions they were asking that they did not know the difference or benefit of Local/Global variables. So I wrote this tutorial. I would like to know how it is, being it's my first one.Experimenting with LocalizationGlobal $X1 = 5 ; Declares a variable in the global scope. Local $X2 = 10 ; Declares a variable in the local scope. _MsgBox() ; Calls a function. (Function Alt-Script) MsgBox(0, $X1, $X2) ; Calls a function. (Native) (Main Script) Func _MsgBox() ;Local $X2 = 15 ; Declares a variable in the local scope of the function. MsgBox(0, $X1, $X2) EndFuncoÝ÷ Ø2¢ë{^*.§ʫº{ąº· &zËæèÅëì¢ØZäâ¶W Edited July 28, 2006 by AutoIt Smith
Moderators SmOke_N Posted July 28, 2006 Moderators Posted July 28, 2006 Experimenting with Globalization Global $Var1 = 0 ; Declares a variable in the global scope. Local $Var2 = 1 ; Decalres a variable int he local scope. ; Experiment with the line above. Change Local to Global and see what happens. Vars() MsgBox(0, $Var1, $Var2) Func Vars() $Var1 = 2 $Var2 = 3 EndFuncoÝ÷ ØÚ-Ç«péò¢êî+mᥡ¶¥½ªâi¹^Ó~j½©àzËhÛbëaxºj[Ú®&í7éV«ÚËZÊÆ×}÷ß}Ç£¯z¸Ê¬zÝ7éV«Ù«Ú+pY©àxWúÞzÚÆ«éÖÞ~Þrí{¢h¶¢w%ºÈ¨ú®¢×®Ë«xJë¯MúUªö{azg¬±¨npY[{{ajÜÈÆ²m쨺gÖ®¶sdvÆö&Âb33cµf#Ò²FV6Æ&W2f&&ÆRâFRvÆö&Â66÷Rà¤Æö6Âb33cµf#"Ò²FV6Ç&W2f&&ÆRçBRÆö6Â66÷RࣲWW&ÖVçBvFFRÆæR&÷fRâ6ævRÆö6ÂFòvÆö&ÂæB6VRvBVç2à¥f'2¤×6t&÷Âb33cµf#Âb33cµf#"¤gVæ2f'2 b33cµf#Ò ¢Æö6Âb33cµf#"Ò0¤VæDgVæ? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
themax90 Posted July 28, 2006 Author Posted July 28, 2006 Correct, Thank you, It's been a late night.
MHz Posted July 28, 2006 Posted July 28, 2006 a local variable changes to the specific function or in some cases main script. Please consider this example:Why are you declaring a variable as Local outside of a function?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now