Jump to content

Loop within a loop


Recommended Posts

I have this code:

$Log = _FileListToArray("L:\Client\LLS_\Daily\Print\", @YEAR&"*", 2)
    $yyyymmdd1 = 0
    $yyyymmdd2 = IniRead("C:\variables.ini","llstime",1,"0")
    For $i = 1 to $Log[0]
        $aTime = FileGetTime("L:\Client\LLS_\Daily\Print\"&$Log[$i], 1)
            $yyyymmdd1 = $aTime[0] & $aTime[1] & $aTime[2] & $aTime[3] & $aTime[4]
            If $yyyymmdd1 > $yyyymmdd2 Then
                $yyyymmdd2 = $yyyymmdd1
                $LLSRecent = $Log[$i]
                $spot=1
                $Log2 = _FileListToArray("L:\Client\LLS_\Daily\Print\"&$LLSRecent&"\","*One*", 2)
                $yyyymmdd3 = 0
                $yyyymmdd4 = IniRead("C:\variables.ini","llstime",2,"0")
                For $i2 = 1 to $Log2[0]
                    $aTime2 = FileGetTime("L:\Client\LLS_\Daily\Print\"&$LLSRecent&"\"&$Log2[$i2], 1)
                    $yyyymmdd3 = $aTime2[0] & $aTime2[1] & $aTime2[2] & $aTime2[3] & $aTime2[4]
                    If $yyyymmdd3 > $yyyymmdd4 Then
                        $yyyymmdd4 = $yyyymmdd3
                        $LLSRecent2 = $Log2[$i2]
                        $check=IniRead("C:\path.ini","llspath",$spot,"")
                        If $check="" Then IniWrite("C:\path.ini","llspath",$spot,"L:\Client\LLS_\Daily\Print\"&$LLSRecent&"\"&$LLSRecent2)
                    EndIf
                    $spot=$spot+1
                Next
                IniWrite("C:\variables.ini","llstime",2,$yyyymmdd4)
            EndIf
        IniWrite("C:\variables.ini","llstime",1,$yyyymmdd2)
    Next
    Return

and what it does is gets a folder from a path, gets it's sub folders then writes the paths into an ini file moves to the next folder and grabs it's sub folders and so on.

the problem is, if there is no sub folders then the script errors out and closes. how can I step out of the inner loop and back to the main loop if there are no sub folders? currently it gives me an error in $log2 - subscript used with non-array variable.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • Moderators

kaotkbliss,

Include an "If Not IsArray($Log2)" line after the "$Log2 = _FileListToArray(..." line. Then if there are no subfolders you can continue on your way without entering the "For $i2 = 1 to $Log2[0]" loop.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

kaotkbliss,

Include an "If Not IsArray($Log2)" line after the "$Log2 = _FileListToArray(..." line. Then if there are no subfolders you can continue on your way without entering the "For $i2 = 1 to $Log2[0]" loop.

M23

thank you for the help. I added that in then got an error message If with no Then, so I tried to add If Then Next, but of course that didn't work. I figured if I did Then EndIf it would simply end it's own if and simply continue on as before, so what I ended up doing is adding If IsArray($Log2) Then

right after _FileListToArray then added another EndIf after the loop.

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

  • Moderators

kaotkbliss,

That sounds right - besides, if it works it must be! :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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