[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

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
0
pek
Asked:
pek
  • 3
  • 2
1 Solution
 
tureCommented:
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
 
caraf_gCommented:
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
 
crazymanCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
crazymanCommented:
>>>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
 
tureCommented:
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
 
tureCommented:
:o)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now