Microsoft KB Archive/127942

= How to Place a Timer in the Main Window =

Article ID: 127942

Article Last Modified on 2/12/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q127942



SUMMARY
The Timer control is new to Visual FoxPro. It can execute code at regular intervals and is not a visual control. You can use the timer to periodically execute a set of commands. The following two sample programs illustrate the basic commands to place a timer on the Visual FoxPro version 3.0 desktop.



Method One: Use the ADDOBJECT Method to Place the Timer on the Desktop
The _SCREEN system memory variable holds a reference to the main Visual FoxPro window. It allows you to manipulate it as a form. This memory variable will be used in this sample.

The following code places a timer that displays the time. Similar code can be used to place any control on the desktop. Press the F6 key to release the timer.

Place the following code in a program (.PRG) file: * To remove the object: ON KEY LABEL F6 _SCREEN.RemoveObject('oTime')

* To activate the Timer: _SCREEN.AddObject('oTime','MyTimer')

* Class definition. The TIMER event is triggered every second, and a  * WAIT WINDOW is displayed. DEFINE CLASS MyTimer AS Timer Interval= 1000 PROCEDURE Timer WAIT WINDOW (TIME) NOWAIT ENDPROC ENDDEFINE

Method two: Encapsulate the Object in a Container Class
This sample program does the same operations as the first example. The timer is added to a container class, and the CREATEOBJECT function instantiates the object. To execute the sample, place it in a .PRG file and run the program. Press the F6 key to release the timer. PUBLIC oTimerObj

* The instance variable is released when F6 is pressed. ON KEY LABEL f6 RELEASE oTimerObj

oTimerObj=CREATEOBJECT('MyTimer')

DEFINE CLASS MyTimer as Container ADD OBJECT oTimerobj as TimerClock ENDDEFINE

DEFINE CLASS TimerClock as Timer Interval = 1000 PROCEDURE Timer WAIT WINDOW (TIME) NOWAIT ENDPROC ENDDEFINE

Additional query words: VFoxWin

Keywords: kbcode KB127942

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.