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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Progress Meter - Bar Flickers, Not Smooth

Status
Not open for further replies.

dftjsn

Programmer
Feb 25, 2002
43
0
0
US
I've created a progress meter form. In a Public Sub in the progress meter form I have the following code:

Public Sub Progress(lngCurrent As Long, lngTotal As Long)
'Assumes box is 3.5" or 5040 twips wide
Me.rectProgressBar.Width = 5040 * (lngCurrent / lngTotal)
Me.Repaint
End Sub

Private Sub CmdTestIt_Click()
DoCmd.OpenForm "frmProgressBar", acNormal
Dim lngCurrentProgress As Long
For lngCurrentProgress = 1 To 3000
Call Forms("frmProgressBar").Progress(lngCurrentProgress,3000)
Next lngCurrentProgress
DoCmd.Close acForm, "frmProgressBar"
End Sub

This test works OK, but the solid progress bar flickers quite a bit as it proceeds across the rectangle. Everything stays within the rectangle. It just isn't a nice, smooth solid color sliding across the rectangle.

Does anyone have any suggestions?

Thanks,

dftjsn
 
I've run in to the same, using inbuilt progress bar.

In sted of calling it every iteration, call it every 10, 20, 100 time...

HTH Roy-Vidar
 
your problem is probably the speed at which you are testing it. when you are using a progress bar there is normally some computationally expensive work going on in the background between progress updates. you can still update on every step, as opposed to every 10 or so, under such circumstances, because the longer period of time between updates allows the video card and monitor more time to finish drawing the last frame you sent to it before you tell it to start another one.

i would also suggest this simple but significant performance optimization to minimize the resources spent by the progress bar itself:

Dim fpmStep as Single

Public Sub Progress(lngCurrent As Long, lngTotal As Long)

' Assumes box is 3.5" or 5040 twips wide

fpnStep = 5040 / lngTotal ' divide only once

Me.rectProgressBar.Width = fpnStep * lngCurrent
Me.Repaint

End Sub

You might have to play with the datatype of fpnStep, but this general idea should reduce the computational power required by the status meter by a little over 50%

- may seeds of dreams fall from my hands
and by yours be pressed into the ground
 
Roy-Vidar/SpiralMind,

Thanks for the advice. One thing that has me perplexed though is that the bar proceeds smoothly without flicker if I put the computation loop in the same form module as the bar. I seem to only get the flicker when I'm calling the Progress Bar procedure from a different form module that has the computation loop.

Thanks for the performance tip, SpiralMind. I think what you are saying though is that I should compute the step increase:

fpnStep = 5040 / lngTotal ' divide only once

only once before the computational loop. That makes sense.

Thanks!

dftjsn
 
making external function calls does have some associated overhead, but this should not be significant here, and calling the external function allows you to reuse the same code elsewhere if you want another progress bar, so you should probably leave that as it is.

- may seeds of dreams fall from my hands
and by yours be pressed into the ground
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top