PRB: GET VALID Routine Is Not Called When Switching Windows

Last reviewed: April 29, 1996
Article ID: Q99609
The information in this article applies to:
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a
  • Microsoft FoxPro for Windows, versions 2.5 and 2.5a

SYMPTOMS

The GET VALID routine in a program is not called when the user switches between windows either by pressing CTRL+F1 or by choosing Next Window from the window's Control-menu box. To demonstrate this behavior, run the following program:

   DEFINE WINDOW test1 FROM 2,2 TO 10,20 ;
     FLOAT ;
     GROW ;
     CLOSE ;
     SYSTEM ;
     TITLE "TEST1"
   ACTIVATE WINDOW TEST1
   @ 2,2 GET x DEFAULT "Hello!" VALID hello()

   DEFINE WINDOW test2 FROM 12,2 TO 20,20 ;
     FLOAT ;
     GROW ;
     CLOSE ;
     SYSTEM ;
     TITLE "TEST2"
   ACTIVATE WINDOW TEST2
   @ 2,2 GET y DEFAULT "Goodbye!" VALID hello()

   READ CYCLE
   CLEAR ALL

   PROCEDURE hello
     WAIT WINDOW WLAST()

CAUSE

This is the expected behavior for FoxPro.

RESOLUTION

To force the VALID routine to execute, place it in the READ DEACTIVATE clause. The following steps demonstrate how to do this through the FoxPro Screen Builder.

  1. Add the following to the Setup code:

          PUBLIC hasvalid  && Memory variable used to determine if field
    
                           && has associated VALID clause.
          hasvalid = .F.
    
    

  2. In the WHEN snippet for each GET field, add one of the following lines as appropriate:

          hasvalid = .T.   && If the GET field has a VALID routine.
          hasvalid = .F.   && If the GET field does not have a VALID
                           && routine.
    
    

  3. In the VALID snippet for each GET field that has a VALID routine, add the following line as a procedure:

          DO (varread())   && Causes the procedure that is named the same
                           && as the current GET field to execute.
    
    

  4. Define all VALID procedures in the cleanup code. The name of each procedure should be the name of the associated GET field.

  5. Add the following code to the READ DEACTIVATE clause:

          IF hasvalid
    
             DO (varread()) && Named expression to cause proper procedure
                            && to execute. Preferred to macro
                            && substitution.
          ENDIF
          RETURN .F.        && Necessary to keep the READ from
                            && terminating.
    
    
The GET VALID routine is also called when the user switches between windows by clicking on another window.


Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a
KBCategory: kbprg kbprb
KBSubcategory: FxprgMacrosub



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.