How to Create an Object That Performs a Sequential Search

ID: Q119397

2.5x 2.60 | 2.5x 2.60 | 2.50b 2.50c

WINDOWS   | MS-DOS    | MACINTOSH

The information in this article applies to:

- Microsoft FoxPro for Windows, versions 2.5x, 2.6 - Microsoft FoxPro for MS-DOS, versions 2.5x, 2.6 - Microsoft FoxPro for Macintosh, versions 2.5b, 2.5c

SUMMARY

This article explains how to create a screen (.SCX) object that will accept character input, SEEK, and refresh screen objects and Browse windows on a character-for-character basis as each character is entered in the object. The basic process used in this article is to trap for keyboard input while simulating input into a GET field.

MORE INFORMATION

 1. Open the TUTORIAL\CUSTOMER database supplied with FoxPro.

  2. Make certain there is an index tag called COMPANY based on the
    COMPANY field. The code that performs the sequential search is case
    sensitive. If you want the search process to ignore case, base the
    index on the COMPANY field on the UPPER value of the field, then also
    SEEK the UPPER value of mComp.

 3. Create a new screen.

 4. Place the following code in the Setup code snippet:

       DEFINE WINDOW x FROM 20,0 TO 30,50 FLOAT GROW
       BROWSE WINDOW x NOWAIT
       mComp = ''  && null
       SET ORDER TO company

    This will create a Browse window in addition to the main GET screen
    that is used to visually display the searched records.

 5. In FoxPro for Windows and Macintosh, use the Field tool to place an
    input field on the screen with COMPANY as its input expression. (In
    FoxPro for MS-DOS, choose Field from the Screen menu.) Mark the field
    as initially disabled. This field will demonstrate the screen
    expressions being updated as you enter the search expression.

 6. In FoxPro for Windows and Macintosh, use the Field tool again to place
    another input field on the screen with the variable mComp as its input
    expression. (In FoxPro for MS-DOS, choose Field from the Screen menu.)

 7. In the WHEN clause of mComp, place the following code:

       mComp = ''
       SHOW GET mComp
       DO WHILE .T.
          mlast = INKEY(0)
          DO CASE
             CASE mlast = 13  && RETURN Key pressed
                _CUROBJ= OBJNUM(mdone)    && or any object you want next
                SHOW GET mdone
                EXIT
             CASE mlast = 127 && BACKSPACE Key pressed
                mcomp = SUBSTR(mcomp,1,LEN(mcomp)-1)
                SET NEAR ON
                SEEK mcomp
                SET NEAR OFF
                SHOW WINDOW customer REFRESH
                SHOW GETS
             CASE mlast >= 48 AND mlast <= 57  OR;
                   mlast >= 65 AND mlast <= 90  OR;
                   mlast >= 97 AND mlast <= 122 OR;
                   mlast =  32 && 0-9, A-Z, a-z, or Spacebar
                mcomp = mcomp+CHR(mlast)
                SET NEAR ON
                SEEK mcomp
                SET NEAR OFF
                SHOW WINDOW customer REFRESH
                SHOW GETS
             OTHERWISE  && Do nothing, no character to process
          ENDCASE
       ENDDO

 8. Place a Quit push button on the screen.

 9. From the Program menu, choose Generate.

10. In FoxPro for Windows or Macintosh, choose the More button to display
   additional generation options. One of those options is a push button
   labeled "Associated Windows". In FoxPro for MS-DOS, this option appears
   as a check box in the dialog box that opens right after you choose
   Generate.

11. Select the Associated Windows option. Type "customer" (without the
   quotation marks) as the name of the associated window.

12. Finish generating the screen and run it.

To begin entering the name of a company to search for, click the MCOMP field. To leave the input process, you must press the ENTER key.

Additional reference words: FoxMac FoxDos FoxWin 2.50 2.50a 2.50b 2.60 jkey incremental sequential KBCategory: KBSubcategory: FxprgBrowse

Keywords          : kbcode FxprgBrowse 
Version           : 2.5x 2.60 | 2.5x 2.60 | 2.50b 2.
Platform          : MACINTOSH MS-DOS WINDOWS

Last Reviewed: May 22, 1998