How to Keep Cursor in GET Object If Data Is Invalid

Last reviewed: April 30, 1996
Article ID: Q117591
The information in this article applies to:
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b, 2.6
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6
  • Microsoft FoxPro for Macintosh, versions 2.5b, 2.5c

SUMMARY

This article describes how to keep the cursor in a GET object if the data that was entered is invalid.

MORE INFORMATION

The following code examples illustrate two ways of keeping the cursor in a GET object.

Example 1

This example uses a GET field called m.pass and calls a UDF function named Testit() each time the cursor leaves the field. By default, the Testit() function will always return true (.T.), which updates the object with the current value. If invalid or incorrect data was entered in a field, you can return false (.F.), which keeps the original value unchanged in the GET field and displays an "Invalid Input" message.

   *** Code begins here ***
   @ 5,0 GET m.pass DEFAULT '  '  VALID Testit()
   READ CYCLE

   FUNCTION testit
   IF m.pass = "Y"
      RETURN .T.
   ELSE
      RETURN .F.
   ENDIF
   *** Code ends here ***

You can suppress the "Invalid input" message by returning a value of zero (0) instead of .F. For more information on using RETURN 0, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q90415
   TITLE     : Suppressing the "Invalid Input" Message in FoxPro

Example 2

The following code illustrates how you can force the cursor to remain in the same field object by setting the value of _CUROBJ (current object) to itself instead of using RETURN .F. in the called procedure.

   *** Code begins here ***
   @ 5,0 GET m.anyx DEFAULT '     ' VALID Test2()
   @ 6,0 GET m.anyz DEFAULT '     '
   READ CYCLE

   FUNCTION test2
   WAIT WINDOW m.anyx TIMEOUT 5
   _CUROBJ=_CUROBJ
   *** Code ends here ***


Additional reference words: FoxMac FoxDos FoxWin 2.00 2.50 2.50a 2.50b
2.50c 2.60
logical
field
level updates
KBCategory: kbprg kbcode
KBSubcategory: FxprgGeneral


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 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.