Sign in to follow this  
Followers 0
laurin1

For In and Multi Dimensional Arrays

8 posts in this topic

I've not used for in much in AutoIt, but can For In be used with complex arrays? I am trying to simply iterate through an array like this

$a[0][0] = 'testname'

$a[0][1] = 'testnum'

and AutoIt seems to just ignore it.


Keith Davis

MCSA, ZCE, A+, N+

http://www.laurinkeithdavis.com

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

as far as i can tell, no it does not work. you have to loop manually to UBound($array). there might be a function for this around allready. good luck.

Share this post


Link to post
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
Sign in to follow this  
Followers 0