Timer
The Timer Control is a cool little device for creating events that fire at predetermined intervals. This is a great replacement for DO...WHILE and INKEY() loops, which chew up a whole bunch of processor time while counting milliseconds. The timer control is flaky and unpredictable in VFP 3.x. The Fox team has done a great job of bringing this one under control in VFP 5 and later versions. Property | Value | Purpose |
Interval | Numeric | Determines length of time (in milliseconds) between Timer events. |
0 | Timer is disabled. | |
Enabled | .T. | Timer counts down Interval milliseconds and then fires the Timer event. |
.F. | Timer does nothing. |
Event | Purpose |
Timer | Code to be executed when event occurs. |
Method | Purpose |
Reset | Resets the countdown to Interval; does not change Enabled state. |
Example | * RemindMe.Prg * This is a pretty trivial example of a program that accepts * a message and the number of seconds to wait to display that * message. In the meantime, processing can go on as normal in * the foreground. * Pass the message to display, and the * number of seconds to wait to display it. LParameters tcMessage, tnTime _SCREEN.AddProperty("oTimer") _SCREEN.oTimer = CreateObject("RemindTime", ; tcMessage, ; tnTime * 1000) && convert to && milliseconds RETURN DEFINE CLASS RemindTime AS Timer cMessage = "" nTime = 0 Interval = 5000 && check every 5 seconds Procedure Init(tcMessage, tnTime) This.cMessage = tcMessage This.nTime = tnTime EndProc Procedure Timer This.nTime = This.nTime - This.Interval IF This.nTime < 0 && we've exceeded the interval MessageBox(This.cMessage) This.Enabled = .F. RELEASE This ENDIF EndProc EndDefine |
See Also | Interval, Timer Event, Reset Method |
View Updates
Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.