Solved

Timer

Posted on 2002-06-10
13
318 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

789 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