MyEarth Posted February 7, 2014 Share Posted February 7, 2014 Hello, I have read the wiki about array: http://www.autoitscript.com/wiki/Arrays But i have a doubt, if i declare a Global array and i want to set the data, how i can make everything on a single line instead of three? Global $aArray[3] ;~ $aArray[3] = [1,2,3] $aArray[0] = 1 $aArray[1] = 2 $aArray[2] = 3 ConsoleWrite($aArray[0] & @CRLF) On the wiki i see Local ( or Global ) $aArray but i don't want to redeclare the $variable again because i used it in a func and isn't not a good pratice Link to comment Share on other sites More sharing options...
FireFox Posted February 7, 2014 Share Posted February 7, 2014 Hi, That's simple : Global $aArray[3] = [1, 2, 3] _ Br, FireFox. Link to comment Share on other sites More sharing options...
MyEarth Posted February 7, 2014 Author Share Posted February 7, 2014 (edited) Not wait everytime i'll call the function i need to set the variable Global again? I dont' have to learn you nothing but in the "Best coding pratices" you declare a $variable global once at the first time for avoid to redeclare it everytime in a Func Example: Global $aArray[3] SetData(1, 0, 0) SetData(1, 1, 0) SetData(1, 2, 3) ConsoleWrite($aArray[0] & @CRLF) Func SetData($1, $2, $3) Global $aArray[3] = [$1, $2, $3] EndFunc ;==>SetData I that example i have declared $aArray Global for 4 times Always declare your global variables in the global scope, not in the functions. It will prevent another function to use it before its declaration and the declaration is implicit Edited February 7, 2014 by MyEarth Link to comment Share on other sites More sharing options...
FireFox Posted February 7, 2014 Share Posted February 7, 2014 (edited) This syntax reinitializes the array, so you have to "redeclare" it using Global or Local. If your array is Global then you can't have a Local variable with this name otherwise it will overwrite the global one. Br, FireFox. Edited February 7, 2014 by FireFox Link to comment Share on other sites More sharing options...
MyEarth Posted February 7, 2014 Author Share Posted February 7, 2014 Mmm so if i make three lines i don't need to redeclare the $aArray to Global but if i make only one line yes? Is not very understandable to me Link to comment Share on other sites More sharing options...
FireFox Posted February 7, 2014 Share Posted February 7, 2014 The "one line syntax" is an array initialization, you must define all the contents/indexes of the array. If you do e.g : $aArray[0] = 5, you only assign a data to an index of the array like any other variable. Br, FireFox. Link to comment Share on other sites More sharing options...
jchd Posted February 7, 2014 Share Posted February 7, 2014 (edited) If your array is Global then you can't have a Local variable with this name otherwise it will overwrite the global one. That's not it: Global $a = "abc" f() ConsoleWrite("Global $a is still " & $a & @LF) Func f() Local $a = 23 ConsoleWrite("Local $a is " & $a & @LF) EndFunc Edited February 7, 2014 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
FireFox Posted February 7, 2014 Share Posted February 7, 2014 (edited) Hmm I see why he was concerned about having the same var name. Edit : Anyway, it's not related to his issue. Edited February 7, 2014 by FireFox Link to comment Share on other sites More sharing options...
jchd Posted February 7, 2014 Share Posted February 7, 2014 Yep, the isue here is semantical: once strict meaning of "scope", "declaration", "initialization" and "assignment" are understood, the mud will vanish. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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