Solved

How to get elapsed real time on a timer?

Posted on 2000-03-01
6
161 Views
Last Modified: 2006-11-17
I want to have a timeout on a timer.
I have a timer that waits for an answer and if it not get an answer in 50 seconds it should stop the timer.
It should be "real" time (timer start to timer end). Its easy to solve with timer function witch returns seconds after midnigt, but it will return the wrong "realtime", if the timer is activated over midnigt (00:00).
How can I solve this in a easy way?

Regards
0
Comment
Question by:pek
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:ture
ID: 2572121
pek,

Add a Timer control to the form. Then use code similar to this:

Private Sub Command1_Click()
  Timer1.Interval = 50 * 1000
  Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
  Timer1.Enabled = False
  'Add code here that you wish to run after 50 seconds.
End Sub

Ture Magnusson
Karlstad, Sweden
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 50 total points
ID: 2572243
Declare a global or module-level variable:
.... datStart As Date

At program initialisation:
datStart = Now

In your timer_click procedure, calculate Abs(DateDiff("s", datStart, Now))

If this value is greater than your allotted time in seconds, do what you have to do.
0
 
LVL 13

Expert Comment

by:crazyman
ID: 2572254
this sub will wait for a given amount of seconds

sub Wait(Seconds as long)
dim lngNow as long
lngNow=timer
do
   if timer=>lngNow+seconds then exit do
doevents
loop
end sub
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 13

Expert Comment

by:crazyman
ID: 2572261
>>>Its easy to solve with timer function witch returns seconds after midnigt, but it will return the wrong "realtime", if the timer
                           is activated over midnigt (00:00).



Bah... didnt see that bit.
0
 
LVL 22

Expert Comment

by:ture
ID: 2572268
crazyman,

pek wrote in his question:
"Its easy to solve with timer function witch returns seconds after midnigt, but it will return the wrong "realtime", if the timer is activated over midnigt (00:00)."

Your posted code suffers from this problem and will not work correctly if the procedure has to wait past midnight.

/Ture
0
 
LVL 22

Expert Comment

by:ture
ID: 2572270
:o)
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

813 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

10 Experts available now in Live!

Get 1:1 Help Now