tamir Posted January 5, 2005 Share Posted January 5, 2005 hi, i have two lists in a gui window and i want to edit their text. i have a script that make all the gui stuff and here's the relevant part where i edit the lists: ;------------------list number 1----------------------; $list_a = GUICtrlCreateList("", 20, 40, 100) $files_num_a = _FileNum($dir_a) _FilesAddToList($list_a, $dir_a,"", $files_num_a) ;------------------list number 1----------------------; ;------------------list number 2----------------------; $list_b = GUICtrlCreateList("", 250, 40, 100) $files_num_b = _FileNum($dir_b) _FilesAddToList($list_b, $dir_b,"", $files_num_b) ;------------------list number 2----------------------; the function _FileNum gets the number of files in the given folder. $dir_a and $dir_b r both @ScriptDir the function _FilesAddToList suppose to add the files names to the given list: Func _FilesAddToList($listHandle, $targetDir, $type, $filesNumber) If $type == "" Then $type = "*.*" GuiCtrlSetData($listHandle, "") $scan = FileFindFirstFile($targetDir & "\" & $type) For $i = 1 to $filesNumber $scan = FileFindNextFile($scan) If NOT ($scan == "." OR $scan == "..") Then GuiCtrlSetData($listHandle, $scan & "|") EndIf Next EndFunc i think that's all the information u need. the problem is that it's only edit the first list. if i disable the first list's editing the other list editing working good. so what's the problem? Link to comment Share on other sites More sharing options...
ezzetabi Posted January 5, 2005 Share Posted January 5, 2005 (edited) Try: Func _FilesAddToList($listHandle, $targetDir, $type) If $type == "" Then $type = "*.*" $scan = FileFindFirstFile($targetDir & "\" & $type) $list = '' While $scan <> - 1 $file = FileFindNextFile($scan) If @error Then FileClose($scan) ExitLoop EndIf If NOT ($file == "." Or $file == "..") Then $list = $list & '|' & $file EndIf WEnd GUICtrlSetData($listHandle,) EndFunc ;==>_FilesAddToList And... Don't mess with handles. The variant that keep handles must stay untouched until FileClose(9 You dont need $filenumber, how did you had this idea? It is better updating controls only once. Updating a list with a string that starts with pipe destroy the old list. As you see the loop I made make a string that starts with a pipe for this reason, no need for GUICtrlSetData($listHandle, "") Edited January 5, 2005 by ezzetabi Link to comment Share on other sites More sharing options...
tamir Posted January 6, 2005 Author Share Posted January 6, 2005 it works, thanks. i didn't understand that part: While $scan <> - 1 what is it for? can i just write "While 1" ? Link to comment Share on other sites More sharing options...
grakker Posted January 6, 2005 Share Posted January 6, 2005 While $scan <> - 1 It's just error checking. You want it like this to be sure FileFindFirstFile found a file before going into the loop. Link to comment Share on other sites More sharing options...
tamir Posted January 6, 2005 Author Share Posted January 6, 2005 oh ok. Link to comment Share on other sites More sharing options...
MHz Posted January 6, 2005 Share Posted January 6, 2005 it works, thanks.i didn't understand that part:While $scan <> - 1what is it for?can i just write "While 1" ?<{POST_SNAPBACK}>While $scan <> - 1 makes the loop exit, when FileFindNextFile errors to find another file. While 1, does not do this. Link to comment Share on other sites More sharing options...
SlimShady Posted January 6, 2005 Share Posted January 6, 2005 I just did a test. FileFindFirstFile only returns -1 if any of the following is true: - You specify a wildcard that doesn't match any file(s). Except *.* that will return 0 - You specify a directory that doesn't exist Link to comment Share on other sites More sharing options...
tamir Posted January 6, 2005 Author Share Posted January 6, 2005 i have another question: is it possible to let the user select more then 1 option? 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