The information in this article applies to:
- Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
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:
- 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.
- Create a button with Donone as the variable and 'Nothing' as the prompt.
- Create a list box in the screen from Files: *.DBF
- Add the following command to the When Clause of the list box:
WAIT WINDOW Listchoice
- Generate and run the screen.
- Because Listchoice is set equal to CUSTOMER.DBF (or whatever you called
it), that is the file highlighted in the list box.
- 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.
- You must click the new file again for it to display in the Wait Window.
- 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:
- Add the following code in the Setup Code section:
SET DEFAULT TO SYS(2004)+"TUTORIAL"
Toggle = .T.
Listchoice = "customer.dbf"
- 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
- 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.
- 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.
|