Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 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