ligenza Posted September 30, 2005 Share Posted September 30, 2005 (edited) Nothing to see here, please move along. Edited September 30, 2005 by ligenza Link to comment Share on other sites More sharing options...
Shibuya Posted September 30, 2005 Share Posted September 30, 2005 (edited) if that variable is used outside a local scope, it becomes a global variable and takes/changes the value assigned when declared in the global scope, it will not be reinitialised Edited September 30, 2005 by Shibuya The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!" Link to comment Share on other sites More sharing options...
Valik Posted September 30, 2005 Share Posted September 30, 2005 Easiest explained by code: Global $variable = "Foo" MsgBox(0, "", "Printfs 'Foo'=" & $variable) function() MsgBox(0, "", "Printfs 'Bar'=" & $variable) Func function() Dim $variable = "Bar"; This is NOT a new local variable EndFunc Compared to this which uses explicit scope qualification (Local/Global can be used to dim arrays, too): Global $variable = "Foo" MsgBox(0, "", "Printfs 'Foo'=" & $variable) function() MsgBox(0, "", "Printfs 'Foo'=" & $variable) Func function() Local $variable = "Bar"; Hide the variable at global scope MsgBox(0, "", "Printfs 'Bar'=" & $variable) EndFunc Link to comment Share on other sites More sharing options...
ligenza Posted September 30, 2005 Author Share Posted September 30, 2005 (edited) Easiest explained by code:Global $variable = "Foo" MsgBox(0, "", "Printfs 'Foo'=" & $variable) function() MsgBox(0, "", "Printfs 'Bar'=" & $variable) Func function() Dim $variable = "Bar"; This is NOT a new local variable EndFuncCompared to this which uses explicit scope qualification (Local/Global can be used to dim arrays, too):Global $variable = "Foo" MsgBox(0, "", "Printfs 'Foo'=" & $variable) function() MsgBox(0, "", "Printfs 'Foo'=" & $variable) Func function() Local $variable = "Bar"; Hide the variable at global scope MsgBox(0, "", "Printfs 'Bar'=" & $variable) EndFuncThanks.Can't I just do this and get the same result? I'm not seeing the need for Dim.Global $variable = "Foo" MsgBox(0, "", "Printfs 'Foo'=" & $variable) function() MsgBox(0, "", "Printfs 'Bar'=" & $variable) Func function() ;Dim $variable = "Bar"; This is NOT a new local variable $variable = "Bar" EndFunc Edited September 30, 2005 by ligenza Link to comment Share on other sites More sharing options...
Shibuya Posted September 30, 2005 Share Posted September 30, 2005 So it is a local unless used as a global? if the variable appears anywhere out of the local scope, it becomes a global variabletake this for example:Func Test1() Dim $var = "Tesing";this variable is declared inside a function, which is supposed to be local Msgbox(0, "", $var) EndFunc Func Test2() Msgbox(0, "", $var); now the variable is being used outside Test1(), becomes global EndFuncso when Test2() is called, the output will be "Testing", even the variable is not declared and assigned a value inside the function The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!" Link to comment Share on other sites More sharing options...
Valik Posted September 30, 2005 Share Posted September 30, 2005 Yes, your example is the same. However, Dim predates Global/Local and as such it has some... weird scoping rules. IMO, Dim should be deprecated in favor of the explicit qualifiers Local/Global but I've never pushed for this. Link to comment Share on other sites More sharing options...
Shibuya Posted September 30, 2005 Share Posted September 30, 2005 i suppose it's convenient? i've never used "global" or "local" so far, only dim The speed of sound is defined by the distance from door to computer divided by the time interval needed to close the media player and pull up your pants when your mom shouts "OH MY GOD WHAT ARE YOU DOING!!!" Link to comment Share on other sites More sharing options...
ligenza Posted September 30, 2005 Author Share Posted September 30, 2005 i suppose it's convenient?i've never used "global" or "local" so far, only dimYeah I suppose. Thanks for all the feedback. Link to comment Share on other sites More sharing options...
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