VB6 app - Get city name from postal code


I have an application were i use ZIP / Postal code in TEXT1.text.

I wanted to validate that ZIP or Postal code in Canada POST or USPS com and get the city name that link to it.

USPS link: https://tools.usps.com/go/ZipLookupAction!input.action

Canada Post link http://www.canadapost.ca/cpotools/apps/fpc/personal/findAnAddress?execution=e1s1

So if for example i have in Text1 the postal code: L1Z 0B5 in Canada Post, i would have AJAX.

Is that something possible?

Thanks again for your help.
LVL 11
Who is Participating?
GrahamSkanConnect With a Mentor RetiredCommented:
Yes, it can be probably be done from the Canada Post link, but it would require a lot of time and expertise.

The process is know as 'Screenscraping' and you would use a Webbrowser control to automate an Internet Explorer simulation.

You would have to  navigate to the page via the URL, wait for the page to appear, fill in the post code, submit, way for the data to be returned and extract it.

Here is an extract of the HTML page to show where the text would be put

<br /><input id="postalCode" name="postalCode" type="text" value="L1Z 0B5" /> Example: A8A 8A8

Open in new window

and here is an extract of the return information
</td><td>2-16<br id="listPostalCodeResult:fpcResultsTable:0:fpc_psn_common_fpct_tag_1" />Even</td><td> </td><td> WESTRAY CRES</td><td></td><td>AJAX</td><td>ON</td><td><script type="text/javascript"><!--
function oamSetHiddenInput(formname, name, value){var form = document.forms[formname];if(typeof form.elements[name]=='undefined'){var newInput = document.createElement('input');newInput.setAttribute('type','hidden');newInput.setAttribute('id',name);newInput.setAttribute('name',name);newInput.setAttribute('value',value);form.appendChild(newInput);}else{form.elements[name].value=value;}}function oamClearHiddenInput(formname, name, value){var form = document.forms[formname];if(typeof form.elements[name]!='undefined'){form.elements[name].value=null;}}function oamSubmitForm(formName, linkId, target, params){var clearFn = 'clearFormHiddenParams_'+formName.replace(/-/g, '\$:').replace(/:/g,'_');if(typeof eval('window.'+clearFn)=='function'){eval('window.'+clearFn+'(formName)');}if(typeof window.getScrolling!='undefined'){oamSetHiddenInput(formName,'autoScroll',getScrolling());}var oldTarget = '';if((typeof target=='function') && target != null){oldTarget=document.forms[formName].target;document.forms[formName].target=target;}if((typeof params!='undefined') && params != null){for(var i=0; i<params.length; i++){oamSetHiddenInput(formName,params[i][0], params[i][1]);}}oamSetHiddenInput(formName,formName +':'+'_idcl',linkId);if(document.forms[formName].onsubmit){var result=document.forms[formName].onsubmit();if((typeof result=='undefined')||result){document.forms[formName].submit();}}else {document.forms[formName].submit();}if(oldTarget==null) oldTarget='';document.forms[formName].target=oldTarget;if((typeof params!='undefined') && params != null){for(var i=0; i<params.length; i++){oamClearHiddenInput(formName,params[i][0], params[i][1]);}}oamClearHiddenInput(formName,formName +':'+'_idcl',linkId);return false;}
//--></script><a href="#" onclick="return oamSubmitForm('listPostalCodeResult','listPostalCodeResult:fpcResultsTable:0:fpc_psn_common_fpct_postcode_2');" id="listPostalCodeResult:fpcResultsTable:0:fpc_psn_common_fpct_postcode_2" class="pcLink">L1Z 0B5</a></td></tr><tr class="even"><td>
					</td><td>7-11<br id="listPostalCodeResult:fpcResultsTable:1:fpc_psn_common_fpct_tag_1" />odd</td><td> </td><td> WESTRAY CRES</td><td></td><td>AJAX</td><td>ON</td><td><a href="#" onclick="return oamSubmitForm('listPostalCodeResult','listPostalCodeResult:fpcResultsTable:1:fpc_psn_common_fpct_postcode_2');" id="listPostalCodeResult:fpcResultsTable:1:fpc_psn_common_fpct_postcode_2" class="pcLink">L1Z 0B5</a></td></tr></tbody></table>

Open in new window

Note that it could be rather slow if you have many to do and/or have limited bandwidth. Also free service providers like this site often introduce deliberate hindrances such as Captcha to prevent bots from stealing the data in bulk.

In the UK, you can subscribe to a database service that makes it a lot easier. I'm sure that such a thing will available in your country.
Don ThomsonConnect With a Mentor Commented:
For the USA Zip Codes (5 Digits)  you can get them in a CSV format  from http://www.unitedstateszipcodes.org/zip-code-database/
It will cost about 40$  if you plan to use it in a commercial program.

In Canada there is a problem. According to Canada Post it OWNS all Postal Codes and if you want the list - you have to buy it from them.   See - http://www.michaelgeist.ca/content/view/6415/125/

Typical Canadian Govt BS - You would think that anything that would ensure more accurate mailing would be welcomed with open arms - but no - Canada Post sues you if you try to make their job easier.
Wilder1626Author Commented:
Thanks again for your help. I think i will stay with the query manually on the web
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.