How to Bypass the When Clause Default in a List Box

ID: Q129015

2.50 2.50a 2.50b 2.60 2.60a WINDOWS

The information in this article applies to:

SUMMARY

Within a list box, the default behavior for the When Clause is to accept the default value of the variable for processing, even if another item was selected in the list box the first time through. This article shows by example how to bypass this behavior.

MORE INFORMATION

Step-by-Step Example Demonstrating the Default Behavior

Create a screen by following these steps:

1. Initialize the variable Listchoice to a file in your default directory

   by placing the following command in the Setup code of the screen:

   Listchoice = "CUSTOMER.DBF"

   Replace CUSTOMER.DBF with the name of your database if you want.

2. Create a button with Donone as the variable and 'Nothing' as the prompt.

3. Create a list box in the screen from Files: *.DBF

4. Add the following command to the When Clause of the list box:

   WAIT WINDOW Listchoice

5. Generate and run the screen.

6. Because Listchoice is set equal to CUSTOMER.DBF (or whatever you called

   it), that is the file highlighted in the list box.

7. Click another file in the list, and watch as the Wait Window returns
   CUSTOMER.DBF. Then after you close the Wait Window, CUSTOMER.DBF is
   still highlighted. It is as if the other file was never selected.

8. You must click the new file again for it to display in the Wait Window.

9. From this point forward, the list box will update the Wait Window to

   display the name of the file as it is selected

Step-by-Step Example Showing How to Change the Default Behavior

You can change this Default behavior to display the name of each file as it is clicked by following these steps:

1. Add the following code in the Setup Code section:

   SET DEFAULT TO SYS(2004)+"TUTORIAL"
   Toggle = .T.
   Listchoice = "customer.dbf"

2. In the screen, create a list box of prompt files like *.DBF. Make
   Listchoice the variable for the list box. In the WHEN Clause, add
   the following code:

   IF Toggle                  && Is this the first time through
      KEYBOARD '{leftmouse}'  && If so, you want to come right back
      Toggle = .F.   && Allows us to move to the ELSE section next time
   ELSE
      *<This is where the code would go>
      DO WHENTEST WITH Listchoice
   ENDIF

3. In the Cleanup Code, add the following:

   PROCEDURE WHENTEST           && A slight variation of the WAIT WINDOW
      PARAMETERS Lcvar
      DEFINE WINDOW TEST FROM 1,1 TO 5,24 DOUBLE
      MOVE WINDOW TEST CENTER
      ACTIVATE WINDOW TEST
      @2,2 GET Lcvar
      READ TIMEOUT 3
      CLEAR
      RELEASE WINDOW TEST
      toggle=.t.

4. Reset the Toggle to .T. upon activation of the screen to handle the case
   where the user leaves this screen and then return to it at a later time.
   Whenever this screen is reactivated, the Toggle can be reset to .T.

Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 2.60a KBCategory: KBSubcategory: FxtoolSbuilder
Keywords          : kbcode FxtoolSbuilder 
Version           : 2.50 2.50a 2.50b 2.60 2.60a
Platform          : WINDOWS

Last Reviewed: May 22, 1998