Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Posts
    8

    Unanswered: What would be a easy way to enter Zipcodes...

    Using FoxPro 2.5 still...

    They want to just enter the zipcode and it auto enter the City and State so I told them that this just might be too hard and time consuming to do but they just wanted me to find out if there was an easy way to do this.

  2. #2
    Join Date
    Dec 2003
    Posts
    104
    It is quite easy really.
    All you really need is a table with three fields. A field containing the zip code, one for the state, and another for the city. We'll call the table ZIPS and the fields ZIP, STATE and well, CITY. You can download/buy these tables, or acquire a file to import into a Fox table, but I'll let you deal with that.

    Anyway, index the table on the zip code:

    USE zips EXCLUSIVE
    INDEX ON zip TAG zip

    Now in your input screen, where you input the zip code, add a VALID clause to do the lookup. For example:

    STORE SPACE(5) TO m.zip
    STORE SPACE(2) TO m.state
    STORE SPACE(25) TO m.city

    @ 1,1 SAY 'Enter ZIP: ' GET m.zip PICTURE '99999' VALID luzip()
    @ 2, 1 SAY 'City: ' GET m.city PICTURE '@!'
    @ 3, 1 SAY 'State: ' GET m.state PICTURE '!!'
    READ CYCLE

    Then, add a function named 'luzip' to your .PRG:

    FUNCTION luzip
    STORE .F. TO retval
    IF SEEK(m.zip)
    m.city = zips.city
    m.state = zips.state
    SHOW GET m.city
    SHOW GET m.state
    retval = .T.
    ELSE
    WAIT WINDOW 'Zip code not on file' TIMEOUT 2
    retval = .F.
    ENDIF
    RETURN retval
    ************************************************

    Now the above function will force a valid zip to be entered before the user can advance to the next field. That can cause obvious problems.
    If you don't want to force a valid zip to be entered, for instance if the table becomes outdated, just change the RETURN retval line to RETURN .T., and the user can enter the correct city and state.
    Of course, you can add code to update your zips table in that case but that's a whole other critter.
    DSummZZZ

    Even more Fox stuff at
    www.davesummers.net/foxprolinks.htm

  3. #3
    Join Date
    Nov 2002
    Posts
    128
    Provided Answers: 1
    If you want to have the users enter each and every Zipcode, City, and State you can certainly do that as explained above.

    However you "open the door" to entry errors, both typo errors and wrong data errors.

    You might want to consider purchasing a Zipcode + State database (typically about $35) and use it to ensure accuracy of the input.

    Your program can allow the user to enter one or more of the parameters (Zipcode, City, and/or State) and then it can check the accuracy of the entry.

    These type of databases are available on the Net at places such as:
    zipcodedownload.com

    Good Luck,
    JRB-Bldr

  4. #4
    Join Date
    Sep 2006
    Posts
    2
    hi there,

    You might want to try get the information at http://www.zipcodeworld.com . It provides free ZIP Code search and longitude and latitude, as well as distance calculation.

    Cheers,
    yuree

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •