Jump to content
Sign in to follow this  
tamir

problem with gui lists

Recommended Posts

tamir

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?

Share this post


Link to post
Share on other sites
ezzetabi

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 by ezzetabi

Share this post


Link to post
Share on other sites
tamir

it works, thanks.

i didn't understand that part:

While $scan <> - 1

what is it for?

can i just write "While 1" ?

Share this post


Link to post
Share on other sites
grakker

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.

Share this post


Link to post
Share on other sites
tamir

oh ok.

Share this post


Link to post
Share on other sites
MHz

it works, thanks.

i didn't understand that part:

While $scan <> - 1

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

Share this post


Link to post
Share on other sites
SlimShady

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

Share this post


Link to post
Share on other sites
tamir

i have another question:

is it possible to let the user select more then 1 option?

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  

×