The information in this article applies to:
- Microsoft FoxPro for Windows, version 2.5, 2.5a, 2.5b, 2.6, 2.6a
- Microsoft FoxPro for Macintosh, version 2.5b, 2.5c, 2.6a
SUMMARY
To forestall having to scroll through a long list in order to find
recurring instances of a given value in a table (.dbf file), you can choose
to type the desired value in an @...GET field and issue a LOCATE FOR
command to find the first such instance, and then use a CONTINUE command to
find other instances.
This article gives one screen design that populates the list-popup with the
contents of an array created from a SQL SELECT of the appropriate field
from the table. It then coordinates the list's displayed value with the
record values in the table as the LOCATE FOR and CONTINUE commands are
executed.
MORE INFORMATION
Steps to Create Screen and List-Popup
- Set the default directory to Tutorial with the following command:
SET DEFAULT TO SYS(2004) + "Tutorial"
- Create a screen by entering the following command in the Command window:
MODIFY SCREEN TestList
- When the Screen Builder appears, click Screen/Layout on the menu bar.
- In the Screen Layout dialog box, click Code. In the Screen Code dialog
box, click Screen Setup Code, and then click OK twice to expose the
Setup code editing window.
- In the Setup code, enter the following commands:
IF !USED("Customer")
USE Customer in 0
ENDIF
SELECT Customer
SELECT State,Recno() FROM Customer INTO ARRAY aTest
* This assumes that no order has been set on the table Customer.
* If the table is ordered the SELECT - SQL must include an
* ORDER BY clause to place the query results in the same sequence as
* that of the table. A further assumption is that the SELECT will not
* include other numeric fields. Other character fields may be
* included.
Locater = "" && memvar tied to @...GET
Close and save the Setup snippet by pressing CTRL+W
- Click the GET ('ab') tool on the Screen designer toolbar. Place a GET
field text box on the screen, and in the ensuing Field dialog box, type
Locater in the edit box to the right of the Input button.
- Click the Valid button, and then click inside the edit region of the
Code Snippet window. Enter the following commands:
LOCATE FOR State = ALLTRIM(UPPER(locater))
Lookup = ASCAN(aTest,Recno()) && local variable = locate's recno()
mylist = ASUBSCRIPT(aTest,Lookup,1) && position list's display
SHOW GET mylist
Click OK twice to return to the screen. Size the @...GET text box to
permit data entry.
- Click the List tool (ninth from the top) and click the screen to
position the list. In the List dialog box, select the From Array option,
and type aTest in the edit box to the right. To the right of the
Variable button, type mylist in the edit box. Click OK to return to the
screen, and size the List so that it will display several lines of
values.
- Click the Push Button tool (fifth from the top), and place a button
on the screen. In the Push Button dialog box, type Continue in the Push
Button Prompts text editing region. To the right of the Variable button,
type Go_On or some other variable name for the button object. Click the
Valid button, and in the Code Snippet window, click the Procedure edit
region, and enter these commands:
CONTINUE
Lookup = ASCAN(aTest,RECNO()) && Local variable = locate's Record#
mylist = ASUBSCRIPT(aTest,Lookup,1)
SHOW GET mylist
Click OK twice to return to the screen.
- On the Program menu, click Generate, and proceed through the steps
to generate a screen program named TestList.spr from the screen
definition TestList.scx.
- In the Command window, type the following command:
DO TESTLIST.SPR
- In the screen, enter the expression ca in the @...GET text box, press
the ENTER key, and observe the list's display. Click the Continue
button and observe the list's display. Notice the display of the record
number on the status bar.
|