Routine too fast for Form to Update?

J

John

I've got a lengthy routine that can take a few seconds to run and I
thought it would be nice to include a progress bar. The routine is
largely just a loop, so tracking progress is easy. So I put it all
together and the form with the progress bar is shown (modeless), but
it doesn't update. I can break the code (Esc key) and all is working
as it should - counter values, percent complete label , progress bar
width are all correct and update visually when I break the code. And
I can step through the code and all works well. I've even added a
Sleep command to slow things down, with no luck. Can the code be
executing too fast for the form to be visually updated??

I thought it might be something in my longer routine, so I ripped out
the progress bar part and tried it in a new workbook. Same results.
Code for that is below. Can anyone tell why I don't see my form
update?

Basics are that I am updating the parameters of labels on a userform:
1) lblFore is the "bar" and a width of 350 is 100% complete
2) lblPct shows the percent complete value


Thanks,
John




Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)

Sub junk()

UserForm1.Show vbModeless

For i = 1 To 1000
iWidth = i / 1000 * 350
UserForm1.lblFore.Width = iWidth
ipct = i / 1000 * 100
UserForm1.lblPct = ipct

Sleep 100

Next i

UserForm1.Hide

End Sub
 
J

Jim Cone

As shown, your progress code will complete almost instantaneously.
The label width should depend on the actual progress of your lengthy routine (LR).
So if your LR is 10% complete then the value of i passed to the "junk" sub should be 100.

Then, each time the userform is updated (the label width changes) you need to tell Excel to redraw
the form.
Do that with: UserForm1.Repaint
'--
Jim Cone
Portland, Oregon USA .
http://www.mediafire.com/PrimitiveSoftware .
(Permutations Add-in: with option to highlight valid words)





"John" <[email protected]>
wrote in message
news:8ec564af-3e6d-43ff-83be-79ca31f98f14@e21g2000vbz.googlegroups.com...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top