Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Locate using a combination of fields
Message
From
04/04/2002 05:37:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
03/04/2002 22:35:23
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00640694
Message ID:
00640761
Views:
13
>Hi. VFP7 user.
>Usually, I search a small database by:
>LOCATE FOR custnum == (mycust)
>
>This time, I would like to (and am having trouble) searching on
>multiple fields
>My command looks like:
>LOCATE FOR mydbf.custnum + mydbf.invnum + mydbf.store == mycustnum + myinvnum + mystore
>
>It just does not seem to work. I am missing something, but I don't
>know what it it. Help....Randy

Randy,
When you use == operator sizes should match it doesn't automatically size for you. You have multiple workarounds :
-Set exact on
-Trim(dbf.field)
-Match memvar size to that of field's

ie: Using employee as sample
LOCATE FOR first_name == 'Steven' && Fails
LOCATE FOR first_name == PADR('Steven',FSIZE('first_name','employee'))
LOCATE FOR TRIM(first_name) == 'Steven'
lcExact=set('exact')
SET EXACT ON
LOCATE FOR first_name = 'Steven'
set exact &lcExact
Next it would be better to divide search expression to multiple fields so it would be easier to build and you wouldn't need any type conversions if fields are not all chartype. Sampling your search regardless of 'set exact' :
*Sounds already all are char type
LOCATE FOR ;
 mydbf.custnum == padr(myCustNum,fsize('custnum')) and ;
 mydbf.invnum == padr(myInvNum,fsize('invnum')) and ;
 mydbf.store == padr(myStore,fsize('store'))

* padr() approach is safer than trim() because your memvars too might
* have trailing spaces

* If some types were not char - say invnum is integer
LOCATE FOR ;
 mydbf.custnum == padr(myCustNum,fsize('custnum')) and ;
 mydbf.invnum == myInvNum and ;
 mydbf.store == padr(myStore,fsize('store'))
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform