View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
John[_142_] John[_142_] is offline
external usenet poster
 
Posts: 2
Default Routine too fast for Form to Update?

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