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 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
CString CDistanceDlg::Parse(CString &szData)
CString szTmp = "";
int pos = szData.Find("\",", 0);
if (pos == -1)
szTmp = szData;
szTmp = szData.Left(pos);
szData.Delete(0, pos + 2);
Points of Interest
When writing a compound
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 -