Jump to content

Multidimentional array declare


Recommended Posts

I have a litle trouble about multidimentional arrays - I want to make room with a global declare and make the variables later on like this - but get instant error messages...

Global $Var[10][7] // every mother variable has a room for 7 sub variables

$Var[3][3] = 'King'

$Var[3][2] = 'burger'

ConsoleWrite($Var[3][2] & ' ' & $var[3][3] & @CR) // would be 'Burger King'

Is this posible in AutoIt3 or how do I do Multi arrays in autoit...

Is there a Dr. Watson around - Please responce....

Kjactive :(

Link to comment
Share on other sites

Maybe this can explain it:

dim $var[2][3]; multi dimentional

for $x= 0 to 1; $x has 2 elements, 0 and 1
    for $y=0 to 2; $y has [3] elements, 0,1,2
        $var[$x][$y]=$x & "," & $y & @crlf &"this is the information"
   ; I placed the values in each
    Next
Next
msgbox(1,"data is in","")
; replace a few values
$Var[0][0] = 'King'
$Var[1][1] = 'burger'

for $x= 0 to 1
    for $y=0 to 2
        msgbox(1,"data var[" & $x & "][" & $y&"]",$var[$x][$y])
        
    Next
Next
msgbox(1,"your output",$Var[1][1] & ' ' & $var[0][0] & @CR)
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

I have a litle trouble about multidimentional arrays - I want to make room with a global declare and make the variables later on like this - but get instant error messages...

Global $Var[10][7] // every mother variable has a room for 7 sub variables

$Var[3][3] = 'King'

$Var[3][2] = 'burger'

ConsoleWrite($Var[3][2] & ' ' & $var[3][3] & @CR) // would be 'Burger King'

Is this posible in AutoIt3 or how do I do Multi arrays in autoit...

Is there a Dr. Watson around - Please responce....

Kjactive  :(

<{POST_SNAPBACK}>

What kind of error message do you get? When I run your code (only replacing the // by ; !!) it shows me the expected message 'burger King' . No error message at all.

Regards,

-Sven

Link to comment
Share on other sites

Well this was an example script to get it right - the trouble come when I want to dynamic create multidimentional variables as this...

Global $tre[99][7] ; does this mean that there are 99 main entries and every main has 7 sub - this do not produce an error but I can't make it work later in the script that is rather large to include here...

$tre[$a] = MakeTree() // example BUT this line don't get it right!!!!!

;==================================================================

;MakeTree: Make the internal tree structure and return the value

;==================================================================

Func MakeTree() // just example function

Return _ArrayCreate(_Word($tmp[1],1), $tmp[3], $tmp[4], $tmp[5], $tmp[6], $style, $extend, StringReplace(StringMid($tmp[1],10),'"',''))

EndFunc

Is there aDr. Watson around as to explane me about why this won't work, what am I doing wrong...

Kjactive :(

Edited by kjactive
Link to comment
Share on other sites

well for starters

Func MakeTree(); (use; not //) just example function

Return _ArrayCreate(_Word($tmp[1],1), $tmp[3], $tmp[4], $tmp[5], $tmp[6], $style, $extend, StringReplace(StringMid($tmp[1],10),'"',''))
EndFunc

Return will return you imediately to where you called the function, and set that variable to the result you gave it.

so look at this:

$x=myfunc(); $x will always be 1

func myfunc()
return 1
$x=979873454345
endfunc

Global $tre[99][7] ; does this mean that there are 99 main entries and every main has 7 sub

Yes, so you will have $tre[0][0] to $tre[98][6] that is 99 with each having 7 subs

$tre[0][0]

$tre[0][1]

$tre[0][2]

.....

$tre[98][0]

$tre[98][1]

$tre[98][2]

$tre[98][3]

$tre[98][4]

$tre[98][5]

$tre[98][6]

Now for a big thing, you have to call out arrays as multidimentional if they are.

$tre[$a] is a single dimention variable

$tre[$a][0] is a multi dimention variable.

Bad code:

Dim $var[99][7]
$var[11]=5

Has to be:

Dim $var[99][7]
$var[11][0]=5
$var[11][1]=5
$var[11][2]=5
$var[11][3]=7
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

I have submitted an ability to do a multi-dimensional array initialization to JP. Check out the next beta release.

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

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