gcue Posted February 20, 2009 Share Posted February 20, 2009 (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 February 20, 2009 by gcue Link to comment Share on other sites More sharing options...
Authenticity Posted February 20, 2009 Share Posted February 20, 2009 Well, the return then should be out of the loop because you're returning as soon as the first loop gets executed. Link to comment Share on other sites More sharing options...
gcue Posted February 20, 2009 Author Share Posted February 20, 2009 ya i tried that but i didnt get any results that way.. =/ Link to comment Share on other sites More sharing options...
Authenticity Posted February 20, 2009 Share Posted February 20, 2009 (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 February 20, 2009 by Authenticity Link to comment Share on other sites More sharing options...
gcue Posted February 20, 2009 Author Share Posted February 20, 2009 hmm not sure what you mean.. a second check? Link to comment Share on other sites More sharing options...
Authenticity Posted February 20, 2009 Share Posted February 20, 2009 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 More sharing options...
gcue Posted February 20, 2009 Author Share Posted February 20, 2009 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 More sharing options...
Authenticity Posted February 20, 2009 Share Posted February 20, 2009 (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 February 20, 2009 by Authenticity Link to comment Share on other sites More sharing options...
gcue Posted February 20, 2009 Author Share Posted February 20, 2009 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 More sharing options...
Authenticity Posted February 20, 2009 Share Posted February 20, 2009 (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 February 20, 2009 by Authenticity Link to comment Share on other sites More sharing options...
gcue Posted February 20, 2009 Author Share Posted February 20, 2009 (edited) 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 February 20, 2009 by gcue Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now