Solved

VB6 app - Get city name from postal code

Posted on 2013-11-12
3
604 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now