How to Return Field to Original Value After Failed VALID

Last reviewed: April 29, 1996
Article ID: Q95637
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

***************************************************************** * 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
.spr initial
value
false
KBCategory: kbenv kbprg
KBSubcategory: FxenvMemory


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.