Jump to content

For In and Multi Dimensional Arrays


Recommended Posts

If you would iterate through a 2-dim array, it wouldn't be sure in what order you want to iterate through it. You could simulate it though by making a function for reading a 2-dim array into a 1-dim array (for the lines) with 1-dim arrays (the line's contents per line) stored in it's elements, and iterate through the line arrays, line by line, and call that _ForIn2DArray($2dArray,$functionToCallPerElement) or something.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Do you have an example of what's not working for you? Much easier to debug if we can see what your are trying to do.

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

Do you have an example of what's not working for you? Much easier to debug if we can see what your are trying to do.

If you do exactly what he says he does, like the following, you'll see that you don't get a msgbox though you might expect one.

Dim $a[2][2]
$a[0][0]=1
$a[1][0]=2
$a[0][1]=3
$a[1][1]=4

For $x In $a
  MsgBox(0,0,0)
Next

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

AutoIt just ignores it, like it doesn't exist. In PHP I can write the code either way:

$a[0][0] = 1a

$a[0][1] = 1b

$a[1][0] = 2a

$a[1][1] = 2b

foreach($a as $s){

echo $a[0].$a[1].'<br />';

}

results:

1a1b

2a2b

OR

foreach($a as $s){

foreach($s as $x){

echo $x;

}

echo '<br >';

}

results:

1a1b

2a2b

AutoIt appears to just ignore the for in statement on multi arrays.

Edited by laurin1

Keith Davis

MCSA, ZCE, A+, N+

http://www.laurinkeithdavis.com

Link to comment
Share on other sites

Poor mans loop....

Local $a[2][2]
$a[0][0] = '1a'
$a[0][1] = '1b'
$a[1][0] = '2a'
$a[1][1] = '2b'

$string = ""
FOR $i= 0 To UBound($a)-1
    $k = 0
    $string = $string & $a[$i][$k] & @CRLF
    $k +=1
    $string = $string & $a[$i][$k] & @CRLF
NEXT


Msgbox(0,'Test',$string)

not elegant, but may work for you

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

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