Sign in to follow this  
Followers 0
gcue

load a combo with a filefind

11 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



Well, the return then should be out of the loop because you're returning as soon as the first loop gets executed.

Share this post


Link to post
Share on other sites

ya i tried that but i didnt get any results that way.. =/

Share this post


Link to post
Share on other sites

#4 ·  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

Share this post


Link to post
Share on other sites

hmm not sure what you mean.. a second check?

Share this post


Link to post
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...

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

#10 ·  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

Share this post


Link to post
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
Sign in to follow this  
Followers 0