How to Return Field to Original Value After Failed VALIDLast reviewed: April 29, 1996Article ID: Q95637 |
The information in this article applies to:
SUMMARYThe @ ... GET VALID clause allows field-level validation of input during data entry. When invalid data is typed in a GET field, the invalid data remains in the field after the validation routine is performed. You can reset the GET field to its original value if the validation routine fails by using a combination of the WHEN and VALID clauses on the GET command.
MORE INFORMATIONTo restore a database field to its initial value after a failed VALID clause, the original value must be stored to a memory variable upon moving the insertion point to the GET field. If the input fails the VALID routine, the WHEN clause must restore the initial value from this memory variable to the database field. The following code demonstrates this procedure. If the FoxPro version 2.0 screen generator is being used, the DATEWHEN code snippet is entered in the WHEN procedure section and the DATEVAL code snippet is entered in the VALID procedure section of the field. The variable named ISDATEVAL would be initialized in the setup code of the screen. The DATEWHEN procedure would never return .F., since the following code is not intended to prohibit data entry in the IDATE field. For the purpose of this example, the invoice date (IDATE) field cannot contain a date that is more than five days before the current system date. ***************************************************************** * Setup Code ***************************************************************** PUBLIC m.idate, isdateval USE invoices * Initialize a variable that tells whether the date entered in * the IDATE field is valid or not. This variable will be used * in the procedure named DATEWHEN. isdateval=.T. ***************************************************************** * GETS & READ ***************************************************************** @ 10,10 GET idate WHEN datewhen() VALID dateval() READ CYCLE ***************************************************************** * WHEN routine ***************************************************************** PROCEDURE datewhen ***************************************************************** * Check to see if GET is a result of a failed VALID or inputting * new value. If this is a new entry, store current value to memory * variable. If not, put original value back in field. *****************************************************************
IF isdateval m.idate = idate ELSE REPLACE idate WITH m.idate ENDIF isdateval=.T. SHOW GETS***************************************************************** * VALID routine ***************************************************************** PROCEDURE dateval IF idate < date()-5 isdateval=.F. DO datewhen IN sys(16,1) && Force the WHEN clause RETURN .F. && in the calling program. ELSE isdateval=.T. ENDIF |
Additional reference words: VFoxWin 3.00 FoxDos FoxWin 1.02 2.00 2.50 2.50a
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |