Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another Zip Code Validation question!

Status
Not open for further replies.

Kerbouchard

IS-IT--Management
Aug 28, 2002
145
0
0
US
Hi guys,(Very novice at Foxpro)
This is the code I ended up using for a zip code validation check. But when it goes down the table it stops at the zip code and matches the city in that record. But in some cases a zip code has more than one city.
EX. 33146 Miami
33146 Coral Gables
So if it was validating Miami it comes up as a match. But if someone input Coral Gables in city it would come up as invalid because it stops at Miami.
DO CASE
CASE SEEK(ALLT(objsycust.txtarcust_city.Value),"a_zip","city") AND ;
UPPER(objsycust.txtarcust_zip.value)=a_zip.zip
ll_result = .t.

CASE SEEK(ALLT(objsycust.txtarcust_zip.Value),"a_zip","zip") AND ;
UPPER(objsycust.txtarcust_city.value)=a_zip.city
ll_result = .t.

OTHERWISE
=MESSAGEBOX("Zip Code or City is Incorrect.",0+48, ;
"Data Entry Error")
objsycust.txtarcust_city.setfocus()
ll_result = .f.
ENDCASE

How can I set it to accept that a zip code may be valid for more than one city?
Appreciate the help!
 
Just a thought. I would probably use the FOUND() function instead of SEEK(). With FOUND() you can keep going past the first matching record.
 
with the a_zip table set to the zip index

if SEEK(ALLT(objsycust.txtarcust_zip.Value),"a_zip","zip")
if UPPER(objsycust.txtarcust_city.value)!=a_zip.city
skip
if UPPER(objsycust.txtarcust_city.value)!=a_zip.city
ll_result = .f.
endif
else
ll_result = .t.
endif
endif

ONE OTHER METHOD is to create an index on the zip and city
index on zip + city to tag zipcty

then do you seek with this

caution on this index DO NOT trim the city field. this cause extra work for fox and does nothing for performance. Attitude is Everything
 
If you have an index on both the city and zip, you can use a LOCATE command to find it:
[tt]
SELECT a_zip
LOCATE FOR zip=objsycust.txtarcust_zip ;
AND objsycust.txtarcust_city.value
IF FOUND()
&& City and zip combo is valid
ELSE
&& City and zip combo do not exist
ENDIF
[/tt]
If you have your 2 indexes set correctly, then Rushmore will optimize the LOCATE FOR and it should return almost instantly.

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top