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

Running code as an OnOpen event to simulate progress bar

Status
Not open for further replies.

Carthesis

Technical User
Oct 29, 2002
100
GB
Hi,

I've got a splash screen that I'm wanting up when the database starts that will display a 'fake' progress bar while it does some checks in the background.

I've got the code written to fake a progress bar, and it works fine, as long as it works from a command button click. It doesn't however work in the OnOpen, OnCurrent, OnActivate etc. events for the form itself.

Code:
Dim intCurrentProgress As Integer
Dim intWidth As Integer
' This is the number of objects you expect to count which take some
'   time to process.  It likely won't be a constant in your environment.
Dim intTotalWidth As Integer
Const intProgressBarMax As Integer = 20000

intTotalWidth = Me.rectProgressBar.Width

For intCurrentProgress = 1 To intProgressBarMax
    intWidth = (intTotalWidth / intProgressBarMax) * intCurrentProgress
    'MsgBox intWidth
    Me.rectProgressBar.Width = intWidth
    Me.Repaint
Next intCurrentProgress
As I said, works fine from a command button, but in any of the form events, the thing just opens showing the progress bar at 100%.

Any ideas?

I tried inserting a 2 second pause using:
Code:
PauseTime = 2   ' Set duration.
    Start = Timer   ' Set start time.
    Do While Timer < Start + PauseTime
        DoEvents    ' Yield to other processes.
    Loop
    Finish = Timer
immediately before the 'For' loop that runs the progress bar, but that failed to work as it just delayed the opening of the form by 2 seconds.
 
Actually, sorted it now.

Used the OnTimer event with the timer interval set to 500milliseconds, and the first thing the OnTimer Event code does is set the form timer interval to zero, hence disabling any further instances of the thing running.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top