Microsoft KB Archive/133451

= How To Causing a Form or Formset to Time Out =

Article ID: 133451

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q133451



SUMMARY
FoxPro version 2.x provided a TIMEOUT clause on the READ command. If no user input activity occurred during the specified interval, the read operation would stop. You can duplicate this functionality with a timer control on a form in Visual FoxPro. The enhanced event model in Visual FoxPro allows greater control over exactly which events cause a form to time out. For example, you can cause the form to close if the mouse is clicked even though no key was pressed. This article shows you how.



Step-by-Step Example
The following process sets two form level properties (dtKeyPress and dtMouseMove) to store the time of the last keystroke or mouse movement. The timer control verifies the elapsed time since the last occurrence of these two events. If more than the specified interval has elapsed, the form is released.

 Create a new form. Add the following properties to the form:

dtCurrTime

dtKeyPress

dtMousemove

  In the Init method of the form, add the following code: ThisForm.DtKeyPress = DATETIME ThisForm.dtMouseMove = DATETIME   In the KeyPress method of the form, add the following code: ThisForm.dtKeyPress = DATETIME   In the MouseMove method of the form, add the following code: ThisForm.dtMouseMove = DATETIME   Add a timer control to the form. Set the Interval property of the timer to the desired number of seconds * 1000. Add the following code to the TimerEvent method of the timer: lnIntervalInSeconds = This.Interval / 1000 ThisForm.dtCurrTime = DATETIME IF ThisForm.dtCurrTime - ThisForm.dtMousemove >= lnIntervalInSeconds ; AND ; ThisForm.dtCurrTime - ThisForm.dtKeypress > = lnIntervalInSeconds ThisForm.Release ENDIF  Add a text box to the form for testing purposes. Save and run the form. The form should time out and release after the specified number of milliseconds.</li></ol>

Incorporating a Timeout into a Formset
To adapt this example to close an entire formset, follow these steps:


 * 1) Create the three properties specified in step 1 of the example so that they are created at the formset level.
 * 2) Place the Init code specified in step 2 in the Init method of the formset. Change the reference of ThisForm to ThisFormSet.
 * 3) Create the timer control on each individual form in the formset. This is required because the formset itself does not contain KeyPress and MouseMove events. Each form in the formset must maintain its own unique timer, but the formset itself must maintain the information as to whether the user has interacted with any form within the formset. Change all ThisForm references to ThisFormSet within this method.
 * 4) Change the reference of ThisForm in steps 3 and 4 of the example to ThisFormSet.

Additional query words: idle delay

Keywords: kbhowto KB133451

-

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

© Microsoft Corporation. All rights reserved.