Jump to content

Loop Array


rootx
 Share

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

Link to comment
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)
Link to comment
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 :x

Link to comment
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)
    _ArrayAdd($imgArray, "")
    $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)

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

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

Link to comment
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)
    _ArrayAdd($imgArray, "")
    $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

:sorcerer:

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