Solved

VB6 app - Get city name from postal code

Posted on 2013-11-12
3
632 Views
Last Modified: 2013-11-13
Hi

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.
0
Comment
Question by:Wilder1626
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 250 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>
				</div>

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.
0
 
LVL 14

Assisted Solution

by:Don Thomson
Don Thomson earned 250 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.
0
 
LVL 11

Author Closing Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

792 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