VB6 app - Get city name from postal code

Posted on 2013-11-12
Medium Priority
Last Modified: 2013-11-13

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.
Question by:Wilder1626
LVL 76

Accepted Solution

GrahamSkan earned 1000 total points
ID: 39641388
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.
LVL 14

Assisted Solution

by:Don Thomson
Don Thomson earned 1000 total points
ID: 39641408
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.
LVL 11

Author Closing Comment

ID: 39646590
Thanks again for your help. I think i will stay with the query manually on the web

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question