boomingranny Posted July 28, 2007 Share Posted July 28, 2007 When i create a global array, then recreate it the data inside is reset - this is great, just what i want! however - when i create a global variable, then recreate it the data is kept... is this by design? example code: ;declare variables func Declare() global $test2 global $test[4] EndFunc Declare() ;set variables for $i= 1 to 3 $test[$i] = "test" next $test2 = "test2" ;output variables Output() ;re-declare variables Declare() ;output them again, now that they have been re-declared Output() Exit func Output () for $i= 1 to 3 msgbox (0, "test:", $test[$i]) next msgbox (0, "test2:", $test2) EndFunc Link to comment Share on other sites More sharing options...
martin Posted July 29, 2007 Share Posted July 29, 2007 When i create a global array, then recreate it the data inside is reset - this is great, just what i want! however - when i create a global variable, then recreate it the data is kept... is this by design? example code: ;declare variables func Declare() global $test2 global $test[4] EndFunc Declare() ;set variables for $i= 1 to 3 $test[$i] = "test" next $test2 = "test2" ;output variables Output() ;re-declare variables Declare() ;output them again, now that they have been re-declared Output() Exit func Output () for $i= 1 to 3 msgbox (0, "test:", $test[$i]) next msgbox (0, "test2:", $test2) EndFunc If a non-array variable is redeclared then the declaration is ignored unless it is a local variable inside a function in which case it is a different variable. If a variable is an array then declaring it again resets all the values, but if you use the ReDim then the values are kept. This shows the effect- ;declare variables Global $test3 =99 global $test[4] Declare(4) ;set variables for $i= 0 to UBound($test)-1 $test[$i] = $i & "test" next $test2 = "test2" ;output variables Output() ;re-declare variables Declare(3) ;output them again, now that they have been re-declared Output() Local $test3 MsgBox(0,"test3 again",$test3) func Declare($max) Local $test3 = 77;this variable is only seen inside the function ;it will be used instead of a global variable of the same name if there is one global $test2 ReDim $test[$max] EndFunc func Output () for $i= 0 To UBound($test) - 1 msgbox (0, "test:", $test[$i]) next msgbox (0, "test2:", $test2) MsgBox(0,"test3:",$test3) EndFunc Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. 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