Jump to content

Array doubt


MyEarth
 Share

Recommended Posts

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

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 by MyEarth
Link to comment
Share on other sites

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 by FireFox
Link to comment
Share on other sites

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

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 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 here
RegExp tutorial: enough to get started
PCRE 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

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 here
RegExp tutorial: enough to get started
PCRE 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

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