Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh a listbox in a loop ?

Status
Not open for further replies.

yakata

Programmer
Dec 13, 2000
30
FR
Hi there,

Got a problem ;-(
I need to seek a directory to find out new subdirectories as soon as they are created.
I use a list box to diplay on screen the content of the 'master' directory and make a "do while" loop, waitin for new directories. When a new one is created, it is not reflected in the list box, so what do i miss ?))))))

Here's the code, TIA for your advice and success in your business (^_^)

Do while ...

file1.refresh
show
y=file1.listcount

for i = 0 to y-1
file1.listindex=i
....
....
next
loop
 
Your code doesn't work because you are using a file list box rather than a directory list box, and file list boxes only display files, not folders.

- Andy.
 
Woops, you're right

my code countains

Do while ...
dir1.refresh
show
y=dir1.listcount

for i = 0 to y-1
dir1.listindex=i
....
....
next
loop

and it does not work, at all ;-((

 
I tried something similar and I think the problem is that you need to add 'DoEvents' after your Dir1.Refresh. I know it sounds simple but it works.

Anyway, you might want to add a delay loop to your code so that it only checks for new folders every couple of seconds rather than doing it continuously. Either stick the code in a timer and set the Interval to 2000 (2 seconds) or do something like this:

T# = Timer + 2
Do While (Timer < T#)
DoEvents
Loop

which will pause for 2 seconds.

The best solution would be to intercept the Windows message which gets kicked out across the system whenever a new folder is created, but you'd need a message intercept control (like MessageBlaster) to do that.

- Andy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top