ID: Q124921
2.50x 2.6x 3.00 WINDOWS kbprg kbtshoot
The information in this article applies to:
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.
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.
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.
This behavior is by design.
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
Keywords : FxprgGeneral
Version : 2.50x 2.6x 3.00
Platform : WINDOWS
Last Reviewed: May 1, 1996