PRB: Valid Clause Not Executed When Leaving Object

Last reviewed: April 30, 1996
Article ID: Q124921
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows versions, 2.5x, 2.6x

SYMPTOMS

When the insertion point is positioned on a popup or a list box, and then the user clicks some other object, such as a push button, code contained in the VALID clause of the popup is not executed.

CAUSE

VALID clauses are executed under two conditions:

- When a user attempts to leave a field.

   -or-

- When a user selects an item from a screen object.

In the latter case, the VALID clause is not executed in either a list box or popup object, because tabbing out of the object or clicking another object on the screen does not constitute leaving an object.

When an element is chosen from either of these objects, only then is the VALID clause code executed.

Although this may seem counter-intuitive, logically this makes sense because tabbing through a list box or popup isn't the same action as selecting an item from the list.

WORKAROUND

To enforce the execution of Valid routines for objects like a list box or a popup, regardless of whether or not an item was chosen, use a flag to determine if the valid has been executed. The following steps explain how to do this. This example assumes that the VALID clause of the list box or popup calls a user defined procedure or function, such as listbox_valid().

  1. Create a flag in the WHEN of the list box or popup, and set it to False:

    lValidDone = .F.

  2. In the VALID procedure or function of the list box or popup set a variable to True:

    lValidDone = .T.

  3. In the WHEN clause of the objects that follow and precede the list box or popup, insert an IF statement to check the value of lValidDone:

    IF lValidDone = .F.

          DO listbox_valid()  && execute the list box Valid routine
    
    ENDIF

The above IF...ENDIF structure may need to be used in the WHEN of any object the user may tab to or select with the mouse after entering the list box or popup.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Problem

Create and run a program containing the following code:

   DEFINE WINDOW "test" ;
        AT 0.000, 0.000 ;
        SIZE 15.615,91.400 ;
        FONT "MS Sans Serif", 8 ;
        FLOAT ;
        NOCLOSE ;
        MINIMIZE ;
        SYSTEM

   CLOSE ALL
   USE SYS(2004)+"\Tutorial\Customer" IN 1
   SELECT company FROM customer INTO ARRAY testarray

   ACTIVATE WINDOW test NOSHOW

   @ 1.846,19.200 GET popval ;
        PICTURE "@^" ;
        FROM testarray ;
        SIZE 1.538,25.167 ;
        DEFAULT 1 ;
        FONT "MS Sans Serif", 8 ;
        STYLE "B" ;
        VALID myvalid1()

   @ 2.423,50.800 GET m.test ;
        SIZE 1.000,23.200 ;
        DEFAULT " " ;
        FONT "MS Sans Serif", 8 ;
        PICTURE "@K" ;
        VALID myvalid2()

   @ 4.692,19.400 GET listval ;
        PICTURE "@&N" ;
        FROM testarray ;
        SIZE 6.615,55.200 ;
        DEFAULT 1 ;
        FONT "MS Sans Serif", 8 ;
        VALID myvalid3()

   @ 12.000,19.400 GET butnval ;
        PICTURE "@*HN Test Button 1;Test Button 2;Quit" ;
        SIZE 1.769,15.000,0.667 ;
        DEFAULT 1 ;
        FONT "MS Sans Serif", 8 ;
        STYLE "B" ;
        VALID myvalid4()

   ACTIVATE WINDOW test

   READ CYCLE

   RELEASE WINDOW test

   ****************[ VALID FUNCTIONS ]****************

   FUNCTION myvalid1     &&  Popval VALID

   WAIT WINDOW "Executing popup Valid routine."

   FUNCTION myvalid2     &&  m.test VALID

   WAIT WINDOW "Executing GET field VALID routine."

   FUNCTION myvalid3     &&  ListVal VALID

   WAIT WINDOW "Executing list box VALID routine"

   FUNCTION myvalid4     &&  ButnVal VALID

   DO CASE
   CASE butnval = 1
        WAIT WINDOW "Pressed button 1"
   CASE butnval = 2
     WAIT WINDOW "Pressed button 2"
   CASE butnval = 3
        CLEAR READ
   ENDCASE


Additional reference words: VFoxWin 3.00 FoxWin 2.50 2.50a 2.50b 2.60 2.60a
tshoot
KBCategory: kbprg kbtshoot
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.