|
// LookUp.cpp : implementation file
//
#include "stdafx.h"
#include "Distance.h"
#include "LookUp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// LookUp dialog
LookUp::LookUp(CWnd* pParent /*=NULL*/)
: CDialog(LookUp::IDD, pParent)
{
//{{AFX_DATA_INIT(LookUp)
m_edit1 = _T("");
m_edit2 = _T("");
//}}AFX_DATA_INIT
}
void LookUp::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(LookUp)
DDX_Control(pDX, IDC_LIST1, m_list1);
DDX_Text(pDX, IDC_EDIT1, m_edit1);
DDX_Text(pDX, IDC_EDIT2, m_edit2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(LookUp, CDialog)
//{{AFX_MSG_MAP(LookUp)
ON_BN_CLICKED(IDC_FINDIT, OnFindit)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// LookUp message handlers
void LookUp::OnFindit()
{
// TODO: Add your control notification handler code here
CWaitCursor wait;
CStdioFile fd;
if(!fd.Open("ZIPCODEWORLD-US-PREMIUM.CSV", CFile::modeRead))
{
AfxMessageBox("Could not opne file!");
return;
}
CString szData;
CString szTemp, szZip, szCity, szState;
CString City, State;
UpdateData(TRUE);
City = m_edit1;
State = m_edit2;
City.MakeUpper();
State.MakeUpper();
while(fd.ReadString(szData))
{
szZip = Parse(szData);
szCity = Parse(szData);
szState = Parse(szData);
if((szCity.Find(City, 0) >= 0) && ((szState.Compare(State) == 0) || (State == "*")))
{
szTemp = szZip;
szTemp += ", ";
szTemp += szCity;
szTemp += ", ";
szTemp += szState;
szTemp += ", ";
szTemp += Parse(szData);
szTemp += ", ";
szTemp += Parse(szData);
szTemp += ", ";
szTemp += Parse(szData);
m_list1.AddString(szTemp);
}
}
fd.Close();
}
CString LookUp::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;
}
void LookUp::OnSelchangeList1()
{
// TODO: Add your control notification handler code here
int item = m_list1.GetCurSel();
CString szStr, szCaption, szText;
m_list1.GetText(item, szStr);
szCaption = "Zip Code Selection:";
szText.Format("You selected:\n [%s]\nIs this correct?", szStr.Left(5));
if(MessageBox(szText, szCaption, MB_YESNO) == IDYES)
{
m_szZip = szStr.Left(5);
SendMessage(WM_CLOSE);
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.