Solved

How to get elapsed real time on a timer?

Posted on 2000-03-01
6
166 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
[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
  • 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
Industry Leaders: 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!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

732 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