Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grid searching again......but for numbers and dates.
Message
 
À
25/05/1997 01:02:09
Vinod Parwani
United Creations L.L.C.
Ad-Dulayl, Jordanie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00033418
Message ID:
00033597
Vues:
42
I modified the Ingrid control adding the following properties:

cFieldType Type of field in grid column C,N,D,T,Y
lContinue Indicates whether we are in CONTINUE mode when using LOCATE search on non-indexed columns
lFound Indicates whether the search has found a match yet.

I modified the KeySeek method to handle searches on the various field types and to provide the continue option when using LOCATE searches:

**
** InGrid KeySeek method
**
LOCAL cHoldAlias, ;
cHoldTag
LOCAL lcNearHold

m.cHoldAlias = ALIAS()
SELECT (THIS.Parent.Parent.RecordSource)
IF !EMPTY(THIS.cLocateExpression)
IF THIS.lContinue
IF THIS.lFound
CONTINUE
THIS.lContinue = .F.
ENDIF
ELSE
GO TOP
DO CASE
CASE THIS.cFieldType = "C"
LOCATE FOR UPPER(EVAL(THIS.cLocateExpression)) = THIS.cSearchString
CASE THIS.cFieldType = "N"
LOCATE FOR EVAL(THIS.cLocateExpression) = VAL(THIS.cSearchString)
CASE THIS.cFieldType = "Y"
LOCATE FOR EVAL(THIS.cLocateExpression) = VAL(THIS.cSearchString)
CASE THIS.cFieldType = "D"
LOCATE FOR EVAL(THIS.cLocateExpression) = CTOD(THIS.cSearchString)
CASE THIS.cFieldType = "T"
LOCATE FOR EVAL(THIS.cLocateExpression) = CTOT(THIS.cSearchString)
OTHERWISE
LOCATE FOR EVAL(THIS.cLocateExpression) = THIS.cSearchString
ENDCASE
ENDIF
ELSE
IF !EMPTY(THIS.cSeekTag)
lcNearHold = SET("NEAR")
SET NEAR ON
m.cHoldTag = ORDER()
SET ORDER TO THIS.cSeekTag
DO CASE
CASE THIS.cFieldType = "C"
SEEK(UPPER(THIS.cSearchString))
CASE THIS.cFieldType = "N"
SEEK(VAL(THIS.cSearchString))
CASE THIS.cFieldType = "Y"
SEEK(VAL(THIS.cSearchString))
CASE THIS.cFieldType = "D"
SEEK(CTOD(THIS.cSearchString))
CASE THIS.cFieldType = "T"
SEEK(CTOT(THIS.cSearchString))
OTHERWISE
SEEK(UPPER(THIS.cSearchString))
ENDCASE
ENDIF
ENDIF
IF NOT EOF()
THIS.lFound = .T.
IF THIS.nHoldRecord#RECNO()
THIS.lSeekMode=.T.
ENDIF
ELSE
THIS.lFound = .F.
GO THIS.nHoldRecord
ENDIF
IF !EMPTY(THIS.cSeekTag)
SET NEAR &lcNearHold
SET ORDER TO m.cHoldTag
ENDIF
IF THIS.lSearchPreview
THIS.Parent.Header1.Caption = THIS.cSearchString
ENDIF
IF USED(m.cHoldAlias)
SELECT (m.cHoldAlias)
ENDIF

The KeyPress method was modified to handle the [Down Arrow] to look for subsequent matches in LOCATE searches. Also added code to allow "/" "." and "," as valid search string characters.

LPARAMETERS nKeyCode, nShiftAltCtrl
PRIVATE m.nElapsedTime

IF THIS.lInGridActive
THIS.nHoldRecord = RECNO()
m.nElapsedTime = SECONDS()-THIS.nLastPress

DO CASE
CASE BETWEEN(m.nKeyCode, 48, 126) OR m.nKeyCode=32 && AlphaNumeric
NODEFAULT
IF nElapsedTime > _DBLCLICK*10
THIS.cSearchString = UPPER(CHR(nKeyCode))
THIS.lFound = .F.
THIS.lContinue = .F.
ELSE
THIS.cSearchString = THIS.cSearchString + UPPER(CHR(m.nKeyCode))
ENDIF
THIS.KeySeek

CASE nKeyCode = 47
NODEFAULT
THIS.cSearchString = THIS.cSearchString + "/"
THIS.KeySeek

CASE nKeyCode = 46
NODEFAULT
THIS.cSearchString = THIS.cSearchString + "."
THIS.KeySeek

CASE nKeyCode = 44
NODEFAULT
THIS.cSearchString = THIS.cSearchString + ","
THIS.KeySeek

CASE m.nKeyCode=127 && Backspace
NODEFAULT
IF LEN(THIS.cSearchString)<1 OR ;
m.nElapsedTime>_DBLCLICK*10
THIS.cSearchString = ""
THIS.lFound = .F.
THIS.lContinue = .F.
IF SET("BELL")="ON"
?? CHR(7)
ENDIF
ELSE
THIS.cSearchString=LEFT(THIS.cSearchString, ;
LEN(THIS.cSearchString)-1)
THIS.KeySeek
ENDIF
CASE m.nKeyCode=7
NODEFAULT

case nKeyCode = 24 && Down arrow
IF NOT EMPTY(THIS.cLocateExpression)
NODEFAULT
THIS.lContinue = .T.
THIS.KeySeek()
ENDIF

OTHERWISE
IF THIS.lSearchPreview
THIS.Parent.Header1.Caption=THIS.cHoldCaption
ENDIF
ENDCASE

THIS.nLastPress=SECONDS()
ENDIF

If you have a situation such as having a charater index based on a numeric column, you can easily modify the LOCATE/SEEK string to match your index. The following expression is used for a numeric column (Account_No) to search against a compund indext of STR(Account_No,15)+STR(Company,4)

SEEK (PADL(THIS.cSearchString, 15, " "))

I use something just a little more complicated to allow a search on Company and Account_No for the Company column against an index of STR(Company,4)+STR(Account_No,15)

* Build seek expression
lcSeekCompany = LEFT(THIS.cSearchString,4)
IF LEN(TRIM(THIS.cSearchString)) > 4
lcSeekAccount_No = PADL(SUBSTR(THIS.cSearchString,5),15," ")
ELSE
lcSeekAccount_No = ""
ENDIF

SEEK lcSeekCompany + lcSeekAccount_No

Hope this helps

Steve Ruhl
sruhl@cyberjunction.net


>>I have modified the Ingrid control to handle numeric, date, and datetime data. I also added the ability to use the down arrow key to find subsequent matches when using the control in locate mode. I also have a sub-class of the control that seeks in a character index from a numeric column. If you are interested, I can send you the code.
>>
>>Steve Ruhl
>>sruhl@cyberjunction.net
>
>
>I am very much interested, pls send me :-
>
>alpine@emirates.net.ae
Steve Ruhl
CitiMortgage, Inc.
steven.ruhl@citibank.com Office
Steve@steven-ruhl.com Home
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform