Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timer function problem 2

Status
Not open for further replies.

wansink

Programmer
Oct 2, 1999
1
US
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.<br>
<br>
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.<br>
<br>
I'd appreciate any thoughts as to what might cause this to happen.
 
You might try ending the program when the timer value &gt;= start value + 600 seconds. Not too precise but, at least, the program will end.
 
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.
 
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.<br>
The world refuses to stop spinning while we wait for a sparrow to fall.<br>

 
Alt255, not sure I get you... do you mean it would be hard to implement a range such as :<br>
timer value &gt;= start value + 600 seconds and &lt;= start value + 601 seconds?
 
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<br>
<br>
Option Explicit<br>
'API Declares<br>
Private Declare Function GetTickCount Lib &quot;kernel32&quot; () As Long<br>
<br>
'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:<br>
Static curtime As Long<br>
Dim timenow As Long<br>
Dim timediff As Long<br>
'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 <br>
<br>
If curtime = 0 Then<br>
timenow = GetTickCount<br>
curtime = timenow<br>
Else<br>
timenow = GetTickCount <br>
End If<br>
timediff = timenow - curtime<br>
<br>
You now have the elaspsed time since the event was first called.<br>
<br>
<br>
Hope this is usefull<br>
<br>
<br>
Sparrow
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top