Click here to Skip to main content
Click here to Skip to main content
Go to top

Distance

, 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

Introduction

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.

Background

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 zipcode.zip 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;
        szTmp.Remove('\"');
        return szTmp;
    }
    // Save data, remove from left
    szTmp = szData.Left(pos);
    szData.Delete(0, pos + 2);
    szTmp.Remove('\"');
    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 == "*"))

History

  • 9 May, 2005 - Version 1.0.

Credits

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

License

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

Share

About the Author

Roger65

United States United States
No Biography provided

Comments and Discussions

 
GeneralUsing my own data PinmemberAlex Evans10-May-05 20:19 
GeneralRe: Using my own data PinmemberRoger6511-May-05 2:41 
GeneralCould not open ZipCode zip file. PinmemberWREY10-May-05 9:42 
GeneralRe: Could not open ZipCode zip file. PinmemberRoger6510-May-05 10:12 
If you downloaded the Demo and you are trying to open zipcode.zip with WinZip or some program you can't. Only the zipdll.dll can.
 
Old dog learning new tricks!
GeneralVery Cool. PinmemberWREY10-May-05 13:24 
QuestionCanadian postal codes too? PinmemberNGS 54967210-May-05 5:22 
AnswerRe: Canadian postal codes too? PinmemberRoger6510-May-05 5:43 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 10 May 2005
Article Copyright 2005 by Roger65
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid