Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Seek() with wildcards (*?)
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00506837
Message ID:
00506845
Views:
16
>I am rewriting an application originally done in Access (by someone else). The application uses an Access filtering function were wildcards can be used to search for data. The client very often gets partial information fron the customer and has to search for container # "TEST12345MI" by using "*12345*". Is there a way to use wildcards with FoxPro seek(). I am probably going to do some kind of search using at() unless someone has a better suggestion. The filtering method being used in the Access application is very slow and I would like to improve the speed.

This code is what I use when the user is allowed to enter some filtering data on a nomenclature field.
IF NOT EMPTY(THIS.PARENT.C40txtDocNomen.VALUE)
  llCriteriaEntered = .T.
  LOCAL lcDocValue
  lcDocValue = ALLTRIM(THIS.PARENT.C40txtDocNomen.VALUE)
  IF AT_C('*',lcDocValue,1) = 0
    * The user entered a search with no wild card characters
    lcFilter = lcFilter + ' AND docNomen = "'+ lcDocValue +'"'
  ENDIF
  IF LEN(lcDocValue) = AT_C('*',lcDocValue,1)
    * The user entered a wildcard in last position, so lets remove it and set the filter
    lcDocValue = SUBSTR(lcDocValue,1,LEN(lcDocValue)-1)
    lcFilter = lcFilter + ' AND docNomen = "'+ lcDocValue +'"'
  ENDIF
  IF AT_C('*',lcDocValue,1) > 0 AND AT_C('*',lcDocValue,2) > 0
    * The user entered 2 wildcard search characters so they wish to perform a contains search
    * lets remove the wildcard characters and set the filter
    lcDocValue = STRTRAN(lcDocValue,'*','')
    lcFilter = lcFilter + ' AND "'+ lcDocValue +'" $ docNomen'
  ENDIF
  IF AT_C('*',lcDocValue,1) = 1 AND AT_C('*',lcDocValue,2) = 0
    * The user entered a wildcard at the start only
    * so this would be treated as a contains also
    lcDocValue = STRTRAN(lcDocValue,'*','')
    lcFilter = lcFilter + ' AND "'+ lcDocValue +'" $ docNomen'
  ENDIF
ENDIF
I also have used an SQL query using the LIKE operator to get my records into a cursor. LIKE %lcValueEntered%
  DO CASE
  CASE OCCURS('*',mlotnumber) = 0
    mwhere = mwhere + 'AND LOTLOTCARD.LOTNUMBER = "'+(mlotnumber)+'" '
  CASE (OCCURS('*',mlotnumber) = 1) AND (LEN(mlotnumber) = AT('*',mlotnumber))
    mchop = AT('*',mlotnumber) - 1
    mlotnumber = SUBSTR(mlotnumber,1,mchop)
    mwhere = mwhere + 'AND LOTLOTCARD.LOTNUMBER = "'+(mlotnumber)+'" '
  OTHERWISE
    mlotnumber = CHRTRAN(mlotnumber,'*','%')
    mwhere = mwhere + 'AND LOTLOTCARD.LOTNUMBER LIKE "'+(mlotnumber)+'" '
    mhardsrch = .T.
  ENDCASE
Bret Hobbs

"We'd have been called juvenile delinquents only our neighborhood couldn't afford a sociologist." Bob Hope
Previous
Reply
Map
View

Click here to load this message in the networking platform