Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

timer function problem

timer function problem

timer function problem

I wrote a program that I want to terminate after a certain amount of time expires. I call a function to start the timer (I didn't use the timer control because the time interval is 10 minutes). In the function I set a start value that is equal to the timer's current value. Then I ask the function to call a sub routine that ends the program when the timer's value is equal to the start value + 600 seconds.

On my home PC this program always works fine. However, when I load it on old 486's at work the program works sometimes, but not always. Sometimes the timer fails to end the program. There doesn't appear to be any rhyme or reason - I can run the program twice and do the exact same things in the program and the timer will work one time and not the next.

I'd appreciate any thoughts as to what might cause this to happen.

RE: timer function problem

You might try ending the program when the timer value >= start value + 600 seconds. Not too precise but, at least, the program will end.

RE: timer function problem

In case it is a matter of your clock time on those 486's being too slow to catch the exact time, you might try trapping the value when you use the above code. Maybe you would have to give it a range rather than an exact milisecond. Finding out the clock speed of the slowest 486 might give you a better idea of what a reasonable range is.

RE: timer function problem

Elizabeth, good suggestion but hard to implement on unknown systems (we all deal with them from time to time, or all the time). It's hard to nail a given millisecond on most systems because events are not held in suspension while other events take place.
The world refuses to stop spinning while we wait for a sparrow to fall.

RE: timer function problem

Alt255, not sure I get you... do you mean it would be hard to implement a range such as :
timer value >= start value + 600 seconds and <= start value + 601 seconds?

RE: timer function problem

The following is taken from an article by John Percival about making a lander game. It uses the timer event but actually calulates elapsed time since first called. This may be usefull for you

Option Explicit
'API Declares
Private Declare Function GetTickCount Lib "kernel32" () As Long

'Although the timer is set to go off every millisecond, it does not really fire 1000 times every second, so we must 'find another way to measure the time between one call and the next. We will do this by using a static variable. 'This kind of variable retains its value between callings of a procedure. Therefore, if its value is set to 1 at the end of 'one calling, it will still be 1 next time it is called. Put these declarations into the Timer event:
Static curtime As Long
Dim timenow As Long
Dim timediff As Long
'The GetTickCount API function returns the number of milliseconds elapsed since Windows started, so this is 'ideal. During each timer event, the static variable will be set with the number of milliseconds, then the next time 'the event is raised, we can work out how long it was since the last time the event was called

If curtime = 0 Then
timenow = GetTickCount
curtime = timenow
timenow = GetTickCount
End If
timediff = timenow - curtime

You now have the elaspsed time since the event was first called.

Hope this is usefull


RE: timer function problem

Nice snip, Sparrow, sorry about our spinning world. Elizabeth, even a 486 should be able to catch a one second range (unless there is more than a second of dedicated disk activity) but wansink wants to know how to terminate the program after ten minutes has expired. If the app is set to check for a range of ticks and misses it, the app fails to terminate and continues to check for another 24 hours. If the app checks to see if ten minutes has expired it is certain to succeed.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close