?
Solved

Timer

Posted on 2002-06-10
13
Medium Priority
?
321 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:Barb0400
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +3
13 Comments
 
LVL 2

Expert Comment

by:mmcmillen
ID: 7067846
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.
0
 
LVL 5

Expert Comment

by:rpai
ID: 7067852
Yes, in the Form_load simply set the Timer Interval to 3000.

0
 
LVL 5

Expert Comment

by:rpai
ID: 7067863
..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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Barb0400
ID: 7067866
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
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 7067883
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
0
 
LVL 3

Expert Comment

by:nichia
ID: 7067894
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

0
 
LVL 18

Accepted Solution

by:
Crash2100 earned 150 total points
ID: 7067897
Why don't you just do something like this?


'start processing

Dim EndTime As Date
EndTime = DateAdd("s", 3, Date + Time)

Do While Date + Time < EndTime
    DoEvents
Loop

MsgBox "done!"
0
 

Author Comment

by:Barb0400
ID: 7067902
I don't want to use the Sleep API, i just want the previously executed code to catch up...
0
 
LVL 5

Expert Comment

by:rpai
ID: 7067940
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
0
 
LVL 3

Expert Comment

by:nichia
ID: 7068000
>>"I just want the previously executed code to catch up"

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

0
 

Author Comment

by:Barb0400
ID: 7068006
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?
0
 
LVL 5

Expert Comment

by:rpai
ID: 7068048
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.
0
 
LVL 3

Expert Comment

by:nichia
ID: 7068094
You can use the _BeforeClick event to do all this processing.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question