Creating the COM Object
Option
1 : Create "early bound" COM object
Add
a COM Reference to our COM object, “ISimplyPostCodeCOMClass”
SimplyPostCodeLookup.dll, within your programming language.
Example to create "early bound" COM Object
So we first create the COM object:
Dim SimplyPostCodeLookup As New
SimplyPostCode
This
has the advantage that your programming environment will help with
syntax, and report compile errors, etc. On the down side, if
the object has not been installed on the client computer then the
program will probably crash on execution.
Option 2 : Create a "late bound" object
Example o create "late bound" COM Object
Dim SimplyPostCodeLookup As Object
Set SimplyPostCodeLookup =
CreateObject("ISimplyPostCodeCOMClass.SimplyPostCode")
This
method has the advantage you can handle any errors cause by not
having the COM object installed, but your programming environment
will not help with syntax etc.
You
will then need to dispose of the object when finished.
Best
to use option 1 then switch to option 2 when tested completely.
Specify then Data Key
SimplyPostCodeLookup.SetDataKey(“I_KD352jKKHhk2GAFFKDU”)
The Data Key will have been sent to you via an e-mail when you
opened the account. It
is also available under
the “Data Key” tab of the online admin
window. Note the prefix
“I” or “W” denotes for “Internal” / “Web” use.
You must use the correct
Data Key for Internal/Web use.
[What
is the Web use, Internal use, Full, Thoroughfare and PostZon data
mean?]
Example of Full Postcode Address search data using COM User
Interface
Simply call
SearchForFullAddressWithDialogue(...)
Can be used in local mode [Click
here for more information]
This function call will
display a dialogue box for the user to enter the postcode to search
for. The user then presses the [FIND] button, and a list of
possible addresses is displayed for the entered postcode. The
user selects an appropriate address record and the address is returned.
This takes the following
parameters:
PostcodePrima As String,
Caption As String,
ShowLicienceDetails As Boolean,
AllowManageAccount
As Boolean,
DisplayErrors As Boolean) As Boolean
Returns true if address search completed and
General_credits_display_text contains summary of Credits/License
status.
PostcodePrima allows
you to initiate the search when opened
Caption sets the
caption of the dialogue window
ShowLicienceDetails allows
the dialogue to show License status. It is good practice
to show this information
AllowBuyMoreButton allows
the use to go to their on line account to purchase more licenses
DisplayErrors allows
program to show errors. If off then will simply close and
return errors in General_credits_display_text and
General_errormessage
Example to find Address by Postcode
Function GetAddressByPostcode() As Boolean
On Error GoTo Error_loading
Set SimplyPostCodeLookup =
CreateObject("ISimplyPostCodeCOMClass.SimplyPostCode")
SimplyPostCodeLookup.SetDataKey ("Your Data key")
If SimplyPostCodeLookup.SearchForFullAddressWithDialogue(
"", "Get Address", true,
true, true) then
With SimplyPostCodeLookup
me.CompanyName = .Address_Organisation
me.Line1 = .Address_Line1
me.Line2 = .Address_Line2
me.Line3 = .Address_Line3
me.Town = .Address_Town
me.County = .Address_County
me.Postcode = .Address_Postcode
[Click here for data
returned]
end with
end if
Set SimplyPostCodeLookup = Nothing
Exit_error:
Exit Function
Error_loading:
MsgBox "Simply Post Lookup COM Object has not been installed on
this PC !!! Please install using 'InstallSimplyPostcodeCOM.EXE'"
, vbCritical, "Simply Postcode Lookup software"
Resume Exit_error
End Function
This code displays the
following Postcode Address Lookup window:

Example of Full Postcode Address search data using COM User
Interface, with Advanced search
Simply call
SearchForFullAddressWithDialogueAdv(...)
This function adds an
"Advanced search" button to the above window. This
allows users to enter address words to search for, to return Full address
information.

This function is
identical to the function discussed above, but has one additional
parameter:
PostcodePrima As String,
Caption As String,
PathToStoreData
as string,
ShowLicienceDetails As Boolean,
AllowManageAccount
As Boolean,
DisplayErrors As Boolean) As Boolean
The parameter PathToStoreData
specifies where the COM Object can store data files need
to cache the lookup lists used in the "Advanced Search"
section of the window. This should be on a server so all uses
share the files, therefore one update will update all machines the network.
These updates may be made available periodically (twice a year).
When available an extra button appears allow a user to download the
updates, which should take only take a few seconds.
The Help link takes the user to this
page, click here to view help
The
above search will result in:

See the MS Excel or
Access for a working example of Advanced search
Example of Searching for Thoroughfare
(Street) Address data from Postcode
Simply call GetThoroughfareAddressRecord(Postcode) as
Boolean
Can be used in local mode [Click
here for more information]
Returns true if address search completed and
General_credits_display_text contains summary of Credits/License
status.
If
errors occurred,
General_credits_display_text
or
General_errormessage
contain License/Error description.
Example
code:
With SimplyPostCodeLookup
PostcodeToSearchFor
= “PE13 2QL”
If
.GetThoroughfareAddressRecord(PostcodeToSearchFor) Then
‘Process data
me.Line1 = .Address_line1
me.Line2 = .Address_line2
[Click here for data
returned]
Else
'Show/Handle any errors
MsgBox .General_credits_display_text & vbCrLf &
.General_errormessage, vbCritical,
"Simply Postcode Lookup"
End
If
'Show
Credit/License in form caption
Me.Caption
= .General_credits_display_text
End With
[What
is the Web use, Internal use, Full, Thoroughfare and PostZon data
mean?]
Example of Full Postcode Address search data using your own
UI
Simply call GetFullAddressToList(Postcode) as Boolean,
with the Postcode the user has entered in search box.
Can be used in local mode [Click
here for more information]
Returns true if address search completed and
General_credits_display_text contains summary of Credits/License
status.
If errors occurred, General_credits_display_text or
General_errormessage contain License/Error description.
And
then
call GetFullAddressLineForSelection() to get each line for
list selection
for display
Example code:
First job, get list for address selection.
With SimplyPostCodeLookup
List.clear
PostcodeToSearchFor = “PE13 2QL”
If .GetFullAddressToList (PostcodeToSearchFor) Then
‘Process data
Line = .GetFullAddressLineForSelection()
do until Line = “”
list.AddItem (Line)
Line = .GetFullAddressLineForSelection()
loop
Else
'Show/Handle any errors
MsgBox .General_credits_display_text & vbCrLf &
.General_errormessage, vbCritical,
"Simply Postcode Lookup"
End If
'Show Credit/License in form caption
Me.Caption = .General_credits_display_text
End With
Retrieving residential property only.
To do this simply append “[” to the end of the Postcode.
Retrieving commercial property only.
To do this simply append “]” to the end of the Postcode.
After user selects an address from selection window
Now get Address record, when user double clicks on address line in
selection box
Calling GetFullAddressRecord(SelectedListIndex as long)
Zero
being the first item on the list
Example code:
With SimplyPostCodeLookup
SelectedListIndex = list.ListIndex
If .GetFullAddressRecord (SelectedListIndex) Then
‘Process data
me.Line1 = .Address_line1
me.Line2 = .Address_line2
[Click here for data
returned]
Else
'Show/Handle any errors
MsgBox .General_credits_display_text & vbCrLf &
.General_errormessage, vbCritical,
"Simply Postcode Lookup"
End If
'Show Credit/License in form caption
Me.Caption = .General_credits_display_text
End With
[What
is the Web use, Internal use, Full, Thoroughfare and PostZon data
mean?]
Example of getting Royal Mail PostZon data (Longitude,
Latitude)
Can be used in local mode [Click
here for more information]
This call will retrieve the PostZon Data for a given Postcode,
OSRef, Longitude/Latitude or "Town, County".
This PostZon data is collected from many different source by the
Royal mail. The most useful information is Distance from
Home Postcode (in Kilometers), Longitude and Latitude.
Simply call GetPostZonAddressRecord (Postcode) as Boolean
Returns true if address search completed and
General_credits_display_text contains summary of Credits/License
status.
If errors occurred, General_credits_display_text or
General_errormessage contain License/Error description.
To get the PostZon record
by OSRef, simply set postcode to the OSRef, when
calling GetPostZonData.
To get the PostZon
record by Longtitude/Latitude, (closest within
10Km) set postcode to the "Longtitude|Latitude" (separated
by |).
The Postcode found will be returned in
Address_Rawpostcode.
To get the
Longitude and Latitude
of a Town, simply provide
the Town name + “,SPACE“ + County in the postcode field. The
Longitude and Latitude will then be returned.
[Download town list]
Example code:
With SimplyPostCodeLookup
PostcodeToSearchFor = “PE13 2QL”
.SetHomePostCode(“BH101UI”) ‘Optional for distance
If .GetPostZonAddressRecord(PostcodeToSearchFor) Then
‘Process data
me.lat = .PostZon_latitude_wgs84
me.long = .PostZon_longitude_wgs84
me.Distance = .PostZon_DistanceToHomePostcode
[Click here for data
returned]
Else
'Show/Handle any errors
MsgBox .General_credits_display_text & vbCrLf &
.General_errormessage, vbCritical,
"Simply Postcode Lookup"
End If
'Show Credit/License in form caption
Me.Caption = .General_credits_display_text
End With
Example code, function to get longitude and latitude from postcode:
Function
GetLongLat(PostCode as string, Long as double, Lat as double)
as
boolean
|