Click here to Skip to main content
13,589,782 members
Click here to Skip to main content
Add your own
alternative version


13 bookmarked
Posted 9 May 2005


, 9 May 2005
Rate this:
Please Sign up or sign in to vote.
An article on finding the distance between two Zip codes.

Sample Image


This article allows the user to use Zip code look up from entered city, state information. Then the program will display the distance between the two zip codes.


You will notice the demo project is large, 1.28 MB. A compressed copy of the database is included and is unzipped by the program when started. The file is a private format known only to the included zipdll.dll. When uncompressed, the zipcode.csv file is 8.42 MB which is deleted when the program is closed. The source is a fully functional version if you already have a copy of ZIPCODEWORLD-US-PREMIUM.CSV. The program and database must be in the same directory.

Using the code

To use the program, enter both Zip codes and press the Calculate button. Or, press the Zip Code button and enter city, state. Or, you can enter a * for the state and all states will be listed that match the city. City and state are case insensitive and I used CString.Find() so you only have to enter the first few letters of a city. Caution: if you wanted "New York" and you only entered "New" you will get a long list. Click the desired item in the list box and follow the instructions.

The real worker is the Parse() function:

CString CDistanceDlg::Parse(CString &szData)
    CString szTmp = "";
    int pos = szData.Find("\",", 0);
    // last string, no more seps
    if (pos == -1)
        szTmp = szData;
        return szTmp;
    // Save data, remove from left
    szTmp = szData.Left(pos);
    szData.Delete(0, pos + 2);
    return szTmp;

Points of Interest

When writing a compound if() statement:

if((szCity.Find(City, 0) >= 0) && ((szState.Compare(State) == 0) || (State == "*")))

watch the parentheses. The above works, the code below fills the list box with all 79,614 items.

if((szCity.Find(City, 0) >= 0) && (szState.Compare(State) == 0) || (State == "*"))


  • 9 May, 2005 - Version 1.0.


  • CUnzip class - Florent Jugla
  • Distance function - ZipCodeWorld®


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralUsing my own data Pin
Alex Evans10-May-05 20:19
memberAlex Evans10-May-05 20:19 
GeneralRe: Using my own data Pin
Roger6511-May-05 2:41
memberRoger6511-May-05 2:41 
GeneralCould not open ZipCode zip file. Pin
WREY10-May-05 9:42
memberWREY10-May-05 9:42 
GeneralRe: Could not open ZipCode zip file. Pin
Roger6510-May-05 10:12
memberRoger6510-May-05 10:12 
GeneralVery Cool. Pin
WREY10-May-05 13:24
memberWREY10-May-05 13:24 
QuestionCanadian postal codes too? Pin
NGS 54967210-May-05 5:22
memberNGS 54967210-May-05 5:22 
AnswerRe: Canadian postal codes too? Pin
Roger6510-May-05 5:43
memberRoger6510-May-05 5:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180618.1 | Last Updated 10 May 2005
Article Copyright 2005 by Roger65
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid