PDA

View Full Version : Solved: Progress bar almost working



mqdias
11-22-2012, 03:46 AM
Hi, i think i need some help with my progress bar.
In this webstie i find great this including some examples of progess bars.

As you may see by the attachment, there is a button in Sheet1 named "Show progress" that shows the variety of progress bars that the creator of this file did, and i created my own "CommandButton1" to test it for my use.

I have imported and arranged the code to UserForm2 that i've created, which a has only the progress bar so when i click "CommandButton1" in Sheet1, it starts running the progress bar.

What happens is that when i click the "CommandButton1" the userform isn't shown during the progress bar code and is only showed at the end with the 100% value...

Can anyone give me an idea how can i put the userform to be shown ?

Thanks!

GTO
11-22-2012, 04:31 AM
Hi mqdias,

It is late for me (given that we have a Thanksgiving Holiday in a few hours, not that I am not usually up all-too-late), so just a 'first step' answer:

For your example code, the issue is that you have the pseudo progress bar doing its updating in the form's load/initialize event. At this point, the Object (the form in this case), is being 'built' so-to-speak, but is not yet presented to the user visually.

Move the code under Initialize to the Activate event, and you (or the user) will get to see the now 'built' Object, and the repaints of the progress bar.

Private Sub UserForm_Activate()
labPg1.Tag = labPg1.Width
labPg1.Width = 0
labPg1v.Caption = ""
labPg1va.Caption = ""

' Application.Cursor = xlWait

Dim intIndex As Integer
Dim sngPercent As Single
Dim intMax As Integer

intMax = 100
For intIndex = 1 To intMax
sngPercent = intIndex / intMax
ProgressStyle1 sngPercent, labPg1v.Visible ' labPg1va.Visible
DoEvents
'------------------------
' Your code would go here
'------------------------
Sleep 100
Next

' Application.Cursor = xlDefault
End Sub

Hope that helps,

Mark

mqdias
11-22-2012, 05:38 AM
Thank you very much dear GTO. It worked fine!!!

GTO
11-23-2012, 12:50 AM
You are most welcome, and glad it helped :-)