How to Create an Object That Performs a Sequential Search

Last reviewed: April 30, 1996
Article ID: Q119397
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.

  2. Create a new screen.

  3. 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.

  4. 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.

  5. 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.)

  6. 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
    
    

  7. Place a Quit push button on the screen.

  8. From the Program menu, choose Generate.

  9. 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.

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

  11. 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: kbprg kbcode
KBSubcategory: FxprgBrowse


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.