VBA custom status bar doesn't update properly

T

TFriis

Hi folk.

I've created this custom status bar, but it does not update proper
when the macro is running - any ideas:

code:
frmStatus.lblStatus.Width = 0
frmStatus.Show
for i = 1 to 100 'Slides.count
dblstep = i / 100 'slides.count
frmStatus.lblStatus.Width = dblstep * frmStatus.lblTotal.Width
'Random Code Here.
next i
frmStatus.Hide

The userform (frmstatus) is height: 48,75 and width: 216,75
inside that is two labels, one lblTotal with height: 18 and width: 200
and another lblStatus with height: 18 and width: 10 (and a different
color and placed on top of lblTotal).

When the makro is played, the entire form just turnes white :(
Any ideas?
 
A

Andy Pope

Hi,

Try adding a DoEvents inside your loop.

for i = 1 to 100 'Slides.count
dblstep = i / 100 'slides.count
frmStatus.lblStatus.Width = dblstep * frmStatus.lblTotal.Width

DoEvents

'Random Code Here.
next i

Cheers
Andy
 
E

Edward

DoEvents doesn't do any good here! Office programs are single threaded
programs that means after you pass your control to a userform you need to
execute your code inside the form and then come back to the original code so
you have two optiones here
1) write your code inside the userform ( one of the events like initialize)
2) use a modelss userform frmStatus.Show(modeless)

By the way MS has a nice Progressbar control that you can use on your
userforms
 
T

TFriis

DoEvents doesn't do any good here! Office programs are single threaded
programs that means after you pass your control to a userform you need to
execute your code inside the form and then come back to the original codeso
you have two optiones here
1) write your code inside the userform ( one of the events like  initialize)
2) use a modelss userform frmStatus.Show(modeless)

By the way MS has a nice Progressbar control that you can use on your
userforms  

I got around the problem using a repaint function - thanks for your
help :)
 

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