Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can I SEEK for nearest matched record in CURSOR?
Message
De
29/07/1999 15:25:13
 
 
À
29/07/1999 13:57:34
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00247560
Message ID:
00247911
Vues:
28
Thanks to all of you and especially to Todd for your code of using LOCATE to look for nearest match results without using SEEK(avoid creating unnecessary index files). I have my code running well like this, might be able to share it with others.

fulllen=LEN(mScno)
FOR n = fulllen - 1 TO 1 STEP -1
SELECT mycursor
LOCATE ALL FOR LEFT(mycursor.scno,n)=LEFT(mScno,n)
IF FOUND()
thisform.refresh
thisform.lockscreen=.T.
thisform.Pageframe.pgList.setfocus
thisform.Pageframe.pgList.Grid.refresh
thisform.Pageframe.pgList.Grid.setfocus
thisform.lockscreen=.F.
EXIT
ENDIF
ENDFOR

Todd, I've done this for going to the begining of "B" if the users enter "D".


LOCATE ALL FOR LEFT(mycursor.scno,1)=LEFT(mScno,1)
IF !FOUND()
FOR n=1 TO ASC(LEFT(mScno,1)) STEP 1
LOCATE ALL FOR LEFT(mycursor.scno,1)=CHR(ASC(LEFT(mScno,1))-n)
IF FOUND()
thisform.refresh
thisform.lockscreen=.T.
thisform.Pageframe.pgList.setfocus
thisform.Pageframe.pgList.Grid.refresh
thisform.Pageframe.pgList.Grid.setfocus
thisform.lockscreen=.F.
EXIT
ENDIF
ENDFOR
ENDIF

THanks a lot.

Gan

>Its either that or keep doing locates with ever shrink length of string until you get a hit.
>
>Like this:
>lcmysearch = this.value
>lnstartlen = len(alltrim(lcmysearch))
>locate for field = lcmysearch
>if !found() then
> for lncounter = lnstartlen - 1 to 1 step -1
> locate all for field = left(lcmysearch, lncounter)
> if found() then
> exit
> endif
> next
>endif
>if !found() then
> * the user was a looser and couldn't even get close!
>endif
>
>of course, you might like them to be at the beginning of the R's if they entered Q's, but I'll leave that as a excercise for the student :-)
>
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform