Link to home
Start Free TrialLog in
Avatar of pek
pek

asked on

How to get elapsed real time on a timer?

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
Avatar of ture
ture

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
ASKER CERTIFIED SOLUTION
Avatar of caraf_g
caraf_g

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
>>>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.
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
:o)