Link to home
Start Free TrialLog in
Avatar of Barb0400
Barb0400

asked on

Timer

Ok, I forgot how to use a timer as a pause...

Basically, I want to create a three second pause in a procedure to calculate some numbers...doevents just doesn't cut it.

I set the timer interval to 3000 in the load. Then I enable timer?
Avatar of mmcmillen
mmcmillen

yes that shhould do it.   I'm not sure I understand why you want to do that.  What happens if the calcs take longer than the 3 seconds?

maybe putting your calcs in a function would work better.
Yes, in the Form_load simply set the Timer Interval to 3000.

..And in the Timer Event do the calcs.

Here's and example:-
Private Sub Form_Load()
Command1.Caption = Time
Timer1.Interval = 3000
End Sub

Private Sub Timer1_Timer()
Command1.Caption = Time
End Sub
Avatar of Barb0400

ASKER

when I set tmrProcessing.enabled = true, I want it to wait 3 seconds before going to the next line...

private sub startcalcs()
    If bCancelCheck Then
        bCancelCheck = False
        bLoading = False
        Exit Sub
    End If
   
    tmrProcessing.Enabled = True
   
     Call DisableTabs
   
     Call DoCalcs

end sub


The timer routine looks like this:



Private Sub tmrProcessing_Timer()
    tmrProcessing.Enabled = False
End Sub
Avatar of Mohammed Nasman
Hello

  Use the Sleep API, to pause ur code

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()
  MsgBox "Hello"
  Sleep (3000)
  MsgBox "Hello after 3 seconds"
End Sub
You can use this API function when you need a delay in your program.

The declaration is:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

The sub program is used as in the following example

Sleep 3000 '// 3 second delay

ASKER CERTIFIED SOLUTION
Avatar of Crash2100
Crash2100
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't want to use the Sleep API, i just want the previously executed code to catch up...
Barb0400,
The Timer event would trigger when a preset interval for a Timer control has elapsed (specified in the Interval property).

Something like this might help:-
Private Sub Form_Load()
DoMath
End Sub

Private Sub DoMath()
x = x + 100
Command1.Caption = x & "   " & Time
'-- Pause for 3sec and then proceed with the Math.
Timer1.Interval = 3000
'-- After 3sec the Timer1_Timer event will be triggered
End Sub

Private Sub Timer1_Timer()
'-- Continue with the calculations.
x = x + 100
Command1.Caption = x & "    " & Time
End Sub
>>"I just want the previously executed code to catch up"

Not sure I understand what you mean.  Which code is not "catching up?"

The problem I'm having is when I the user switches tabs. When they hit a tab, the previous tab has to have time to do an "endedit" and a "recalc" before the tab click event actually fires. I just need to put an immediate three second pause in the tabclick event so it can finish calculating the last tab before proceeding. Isn't there a way to have the timer event fire immediately, then wait three seconds and disable it?
The Timer event would fire after waiting for 3 seconds.

So in the tabclick event specify the Timer1.Interval = 3000
And in the Timer1_Timer Event, specify the name of the function that needs to be performed after 3 seconds pause.
You can use the _BeforeClick event to do all this processing.