Solved

Timer

Posted on 2002-06-10
13
314 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
  • 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
 

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:mnasman
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 18

Accepted Solution

by:
Crash2100 earned 50 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now