Microsoft KB Archive/95637

{| = How to Return Field to Original Value After Failed VALID =
 * width="100%"|

ID: Q95637

1.02 2.00 2.50 2.50a | 2.50 2.50a 3.00

MS-DOS              | WINDOWS kbprg The information in this article applies to:
 * Microsoft Visual FoxPro for Windows, version 3.0
 * Microsoft FoxPro for MS-DOS, versions 1.02, 2.0, 2.5, and 2.5a
 * Microsoft FoxPro for Windows, versions 2.5 and 2.5a

SUMMARY
The @ ... 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 INFORMATION
To 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 PROCEDURE dateval
 * * VALID routine *****************************************************************

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 .spr initial value false KBCategory: kbprg KBSubcategory: FxenvMemory Keywords         : kbenv FxenvMemory Version          : 1.02 2.00 2.50 2.50a | 2.50 2.50 Platform         : MS-DOS WINDOWS
 * }