Solved

How to get elapsed real time on a timer?

Posted on 2000-03-01
6
155 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

744 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