How to Keep Cursor in GET Object If Data Is Invalid

ID: Q117591

2.00 2.50 2.50a 2.50b 2.60 | 2.50 2.50a 2.50b 2.60 | 2.50b 2.50c

MS-DOS                     | WINDOWS               | MACINTOSH

The information in this article applies to:

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: KBSubcategory: FxprgGeneral
Keywords          : kbcode FxprgGeneral 
Version           : 2.00 2.50 2.50a 2.50b 2.60 | 2.5
Platform          : MACINTOSH MS-DOS WINDOWS

Last Reviewed: May 22, 1998