Jump to content

load a combo with a filefind


gcue
 Share

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Nope

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

In both cases, first close the search handle.

Edited by Authenticity
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

finally got it - wohoo!

thanks mate

Func LoadCombo()
    
    $cfgs = _FileListToArray(@ScriptDir & "\cfg", "*.cfg")
    If @error = 1 Then
Return "No assets loaded"
    EndIf

    For $c = 1 To $cfgs[0]
        $file &= $cfgs[$c] & "|"
    Next
    Return $file

EndFunc   ;==>LoadCombo
Edited by gcue
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...