# Loop Array

Go to solution Solved by Gianni,

## Recommended Posts

```#include <Array.au3> ; Only required to display the arrays
#include <File.au3>

Local \$imgArray = _FileListToArray("C:\images\", "*.jpg",1)

For \$a = 1 to UBound(\$imgArray) -1
ConsoleWrite("<TR>  "&@CRLF)
ConsoleWrite("  <TD> "&@CRLF)
For \$b = 1 to 5
Next

ConsoleWrite("     "&\$imgArray[\$a]&@CRLF) ;here!!!

For \$d = 1 to 5
Next
ConsoleWrite("  </TD> "&@CRLF)
ConsoleWrite("</TR>  "&@CRLF&@CRLF)
Next```

I would like to have this result, but something wrong, could someone help me?

```<TR>
<TD>
01.jpg
02.jpg
03.jpg
04.jpg
</TD>
</TR>
<TR>
<TD>
05.jpg
06.jpg
N....```

thanks.

##### Share on other sites

are you looking for this...?

```#include <Array.au3> ; Only required to display the arrays
#include <File.au3>
Local \$imgArray = _FileListToArray("C:\images\", "*.jpg", 1)

\$output = ""
For \$a = 1 To UBound(\$imgArray) - 1 Step 4
ConsoleWrite("<TR>  " & @CRLF)
ConsoleWrite("  <TD> " & @CRLF)
\$output &= "<TR>  " & @CRLF & "  <TD> " & @CRLF
For \$b = \$a To \$a + 3
ConsoleWrite("     " & \$imgArray[\$b] & @CRLF) ;here!!!
\$output &= "     " & \$imgArray[\$b] & @CRLF
Next

ConsoleWrite("  </TD> " & @CRLF)
ConsoleWrite("</TR>  " & @CRLF & @CRLF)
\$output &= "  </TD> " & @CRLF & "</TR>  " & @CRLF
Next

MsgBox(64, "now you can use this variable", \$output)```
##### Share on other sites

Thanks Muzaiyan!!!!

Perfect.

I'm really tired today...

##### Share on other sites

when Step it is not a multiple of array does not work,

Ex: if imgArray = 30 the result is wrong... For \$a = 1 To UBound(\$imgArray) - 1 Step 4 ...dimension range exceeded becose 4 is not a multiple of 30

Muzaiyan solution is valid only if you already know the value of the array, in my case I do not know the value before the loop

Any idea? thanks

##### Share on other sites

• Solution

you could add empty elements in array for missing images till total elements is a multiple:

```#include <Array.au3> ; required to manage array
#include <File.au3>
Local \$imgArray = _FileListToArray("C:\images\", "*.jpg", 1)

Local \$Step = 4 ; how many elements per row (you can change this number)

; if not multiple of \$Step then add empty elements in array for missing *.jpg
While \$imgArray[0] / \$Step <> Int(\$imgArray[0] / \$Step)
\$imgArray[0] += 1
WEnd

\$output = ""
For \$a = 1 To UBound(\$imgArray) - 1 Step \$Step ; <- use "\$Step" variable instead of absolute number
ConsoleWrite("<TR>  " & @CRLF)
ConsoleWrite("  <TD> " & @CRLF)
\$output &= "<TR>  " & @CRLF & "  <TD> " & @CRLF
For \$b = \$a To \$a + \$Step - 1 ; <- use "\$Step" variable instead of absolute number
ConsoleWrite("     " & \$imgArray[\$b] & @CRLF) ;here!!!
\$output &= "     " & \$imgArray[\$b] & @CRLF
Next

ConsoleWrite("  </TD> " & @CRLF)
ConsoleWrite("</TR>  " & @CRLF & @CRLF)
\$output &= "  </TD> " & @CRLF & "</TR>  " & @CRLF
Next

MsgBox(64, "now you can use this variable", \$output)```

Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

##### Share on other sites

Nice work!!! Very very thanks!

And then just add an IF to have all rows with no empty rows!!

```#include <Array.au3> ; Only required to display the arrays
#include <File.au3>
Local \$imgArray = _FileListToArray("C:\images\", "*.jpg", 1)

Local \$Step = 9 ; how many elements per row (you can change this number)

; if not multiple of \$Step then add empty elements in array for missing *.jpg
While \$imgArray[0] / \$Step <> Int(\$imgArray[0] / \$Step)
\$imgArray[0] += 1
WEnd

For \$a = 1 To UBound(\$imgArray) - 1 Step \$Step ; <- use "\$Step" variable instead of absolute number
ConsoleWrite("<TR>  " & @CRLF)
ConsoleWrite("  <TD> " & @CRLF)

For \$b = \$a To \$a + \$Step - 1 ; <- use "\$Step" variable instead of absolute number
If \$imgArray[\$b] <> 0 Then ; exit from the loop when the images finish
ConsoleWrite("     " & \$imgArray[\$b] & @CRLF) ;here!!!
Else
ExitLoop

EndIf
Next

ConsoleWrite("  </TD> " & @CRLF)
ConsoleWrite("</TR>  " & @CRLF & @CRLF)

Next```

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...