Jump to content

Recommended Posts

Posted (edited)

im trying to load a combo with a filefindfirstfile/filefindnextfile

its only returning one of the files from the search result...

any ideas?

thank you in advance

$combo = GUICtrlCreateCombo("Select Configuration...", 50, 20, 200, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, LoadCombo(), "Select Configuration...")

Func LoadCombo()
    $search = FileFindFirstFile(@ScriptDir & "\cfg\*.cfg")

    ; Check if the search was successful
    If $search = -1 Then
        MsgBox(0, "Error", "No files/directories matched the search pattern")
        Exit
    EndIf

    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        
        _ArrayAdd($cfgs, $file)
        
        For $i = 1 To $cfgs[0]
            $file &= $cfgs[$i] & "|"
        Next
        Return $file
        
    WEnd
    
    ; Close the search handle
    FileClose($search)

    Return "No assets loaded"
EndFunc   ;==>LoadCombo
Edited by gcue
Posted (edited)

Because you should return $file after @error is not 0 like you did.

Edit: Preform a second check after the error is set to see if $file is an empty string and return "No assets loaded" instead of file (instead of exiting the loop).

Edited by Authenticity
Posted

Within the "If @error Then...EndIf" preform an internal check to see whether $file contain string at all like "If Not StringLen($file) Then Return "No assets loaded" Else Return $file EndIf.

this loop would never be infinite one so don't bother to exit it to return "No assets loaded", instead use Return...

Posted

is this what you meant?

Func LoadCombo()
    $search = FileFindFirstFile(@ScriptDir & "\cfg\*.cfg")

    ; Check if the search was successful
    If $search = -1 Then
        MsgBox(0, "Error", "No files/directories matched the search pattern")
        Exit
    EndIf

    While 1
        $file = FileFindNextFile($search)
        If @error Then
            If Not StringLen($file) Then
                Return "No assets loaded"
            EndIf
        Else
            Return $file
        EndIf
    WEnd
    ; Close the search handle
    FileClose($search)

EndFunc   ;==>LoadCombo
Posted

either im more lost than i thought because this seems like it should work or im totally missing what ur telling me to do... =/

Func LoadCombo()
    $search = FileFindFirstFile(@ScriptDir & "\cfg\*.cfg")

    If $search = -1 Then
        MsgBox(0, "Error", "No files/directories matched the search pattern")
        Exit
    EndIf

    While 1
        $file = FileFindNextFile($search)
        If @error Then
            If Not StringLen($file) Then
                FileClose($search)
                Return "No assets loaded"               
            Else
                FileClose($search)
                Return $file                
            EndIf
        EndIf
    WEnd

EndFunc   ;==>LoadCombo
Posted (edited)

Hmm.. first it's your common sense to see that FileClose can get called right after evaluating If @error to true...

The check has to be preformed first in the head of the loop and don't call things that might change the value of the @error macro in the while or after the FileFindFirstFile() call.

Edit: Why don't you use _FileListToArray and appending the '|' in a For loop?

Edited by Authenticity

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
×
×
  • Create New...