(Code available on CD at “\Sample Code\dtxprocessaddress.asp”) <%@ Language=VBScript %> <% %> <HTML> <HEAD> </HEAD> <!--- Insert:Style Tag -->
<STYLE>A:hover {color:D3D3D3 }A:hover {text-decoration: none}A{text-decoration:none}</STYLE> <!--- Insert:Start Body Tag -->
<BODY BGCOLOR="#ffffff" TEXT="#000000" LINK="#3333ff" ALINK="#3333ff" VLINK="#0000ff" LEFTMARGIN="0" TOPMARGIN="0" >
- 88 -
<TABLE> <TR>
<TD COLSPAN=3 HEIGHT="10" NOWRAP> </TD>
</TR>
<TR><!--- LEFT MARGIN --> <TD WIDTH=6> </TD>
<TD VALIGN="top" width="700"><!--- HEADER --> <TABLE BORDER="0" WIDTH="100%">
<TR><!--- Insert:Start Logo Cell -->
<TD ALIGN="left" VALIGN="top" HEIGHT=80 NOWRAP><!--- Insert:INSERT PAGE LOGO -->
<IMG SRC="http://www.datatools.com.au/letterhead/dtweblogo.jpg" WIDTH=224 HEIGHT=68 ALT="DataTools"> <!--- Insert:End Logo Cell -->
</TD>
<TD ALIGN="right" VALIGN="top" NOWRAP> <FONT SIZE="-2" FACE="Arial" COLOR="#ff0000"> <B>DataTools Pty Ltd</B><BR>
Suite 10, Level 2, 27 Hunter Street, Parramatta NSW 2150<br> PO Box 4187, Parramatta NSW 2124<br> Phone (02) 9687 4666 - Fax (02) 9687 4655<br> www.datatools.com.au<br> </FONT> </TD> </TR> </TABLE>
Powered by the DataTools Rapid Addressing Tool Web Object.<BR><BR> <B>Original Address:</B><BR>
<table border=1 cellpadding=3> <tr> <td><%response.write(unescape(request.querystring("AddressLine")))%></td> <td><%response.write(unescape(request.querystring("LocalityLine")))%></td> </tr> </table> <BR> <%
set dtratobj = Server.CreateObject("DataTools_DtRat.Dtx") status=dtratobj.dtxopen
if status=true then
DtProcessId = dtratobj.DtxCreateProcess
DtResultCode=dtratobj.DtxSearchAddressLineAMAS(DtProcessId,unescape(request.querystring( "AddressLine")),unescape(request.querystring("LocalityLine")))
- 89 - DtDPID=dtratobj.DtxExtractResultField(DtProcessId,"DPID",1) %> <B>Result:</B> <%response.write(dtratobj.DtxConvertErrorCode(DtResultCode))%> <BR><BR> <% If DtDPID = "" then 'DtxIntelliSearchAddressLine DtResultCount=dtratobj.DtxIntelliSearchAddressLine(DtProcessId, unescape(request.querystring("AddressLine")),unescape(request.querystring("LocalityLine"))) if DtResultCount = 9999 then %>
<B>IntelliSearch Component Not Installed </B> <BR>
<%
elseif DtResultCount > 0 then
%><B>IntelliSearch Suggestions:</B> <BR>
<table border=1 cellpadding=3> <% for i = 1 to DtResultCount %>
<tr>
<td>
<%response.write(dtratobj.DtxExtractResultField(DtProcessId,"Address_Line",i))%> </td> <td>
<%response.write(dtratobj.DtxExtractResultField(DtProcessId,"Locality",i) & " " & dtratobj.DtxExtractResultField(DtProcessId,"State",i) & " " &
dtratobj.DtxExtractResultField(DtProcessId,"Postcode",i))%> </td> </tr> <%next%> </table> <% end if else
'Standard AMAS Results %>
<B>Result Details:</B> <BR>
<table border=1 cellpadding=3> <tr> <td> Address Line </td> <td> <%response.write(dtratobj.DtxExtractResultField(DtProcessId,"Address_Line",1))%> </td> </tr> <tr>
- 90 - <td> Locality </td> <td> <%response.write(dtratobj.DtxExtractResultField(DtProcessId,"Locality",1))%> </td> </tr> <tr> <td> State </td> <td> <%response.write(dtratobj.DtxExtractResultField(DtProcessId,"State",1))%> </td> </tr> <tr> <td> Postcode </td> <td> <%response.write(dtratobj.DtxExtractResultField(DtProcessId,"Postcode",1))%> </td> </tr> <tr> <td> DPID </td> <td> <%response.write(DtDPID)%> </td> </tr> <tr> <td> Barcode</td> <td> <%response.write(dtratobj.DtxExtractResultField(DtProcessId,"Barcode",1))%> </td> </tr> <% DtDataChanges=dtratobj.DtxExtractResultField(DtProcessId,"Field_Changes",1) if DtDataChanges <> "" then %> <tr>
<td> Codes for fields that needed to be <BR> repaired to make a correct match</td> <td> <%response.write(DtDataChanges)%> </td> </tr> <% end if %> </table> <% end if dtratobj.DtxDisposeOfProcess DtProcessId dtratobj.DtxClose else
response.write("Could not open DtRAT Object.<BR>")
Response.Write (dtratobj.DtxReturnLastCriticalErrorMessage & "<BR>") end if
set dtratobj = nothing %>
- 91 -
<BR>
<A href="default.htm">Return To Address Entry Page</A> </SCRIPT></TR></TABLE>
</BODY> </HTML>
- 92 -
Sample Server Side VB.Net code
Sample Description
The sample below is made up of threeVB.NET functions.
Sample code
'The object definition, StartRat & EndRat functions below are located in a public module so that they are accessible from both the webservice class and the global file (which has the Application_Start and Application_End methods)
'The object myrat is defined as public:
Public myrat As Object
'Application_Start command (in the Global.asax file) calls the StartRAT function below:
Public Sub StartRat()
'This code gets executed only when the webservice first loads up
myrat = CreateObject("DataTools_DtRat.Dtx") Dim Status As Boolean
'Open Engine once per server
Status = myrat.DtxOpen
'Allocate number of instances
Status = myrat.DtxAllocateRequiredInstances(250) End Sub
'Application_End command (in the Global.asax file) calls the EndRAT function below:
Public Sub EndRat() Dim Status As Boolean
'Close Engine once per server
Status = myrat.DtxClose End Function
'The GetAddressInfo function can be called many times by various users:
<WebMethod()> Public Function GetAddressInfo(ByVal addressline As String, ByVal localityline As String) As String
Try
Dim mystrcol As String Dim mystat As Boolean Dim lngProcessID As Long 'Create thread
lngProcessID = myrat.DtxCreateProcess Dim myres As Integer
myres = myrat.DtxSearchAddressLineAMAS(lngProcessID.ToString, addressline, localityline) mystrcol = ""
mystrcol = myres.ToString
mystrcol = mystrcol.Trim & "*" & myrat.DtxExtractResultField(lngProcessID.ToString, "Address_Line", 1) mystrcol = mystrcol.Trim & "*" & myrat.DtxExtractResultField(lngProcessID.ToString, "Locality", 1) mystrcol = mystrcol.Trim & "*" & myrat.DtxExtractResultField(lngProcessID.ToString, "State", 1) mystrcol = mystrcol.Trim & "*" & myrat.DtxExtractResultField(lngProcessID.ToString, "Postcode", 1)
- 93 - 'Dispose of thread myrat.DtxDisposeOfProcess (lngProcessID.ToString) Return mystrcol
Catch err As Exception Return "ERROR" End Try
- 94 -
Sample Server Side C#.Net code
Sample Description
The sample below is made up of three C#.NET functions.
Sample code
'The object definition, StartRat & EndRat functions below are located in a public module so that they are accessible from both the webservice class and the global file (which has the Application_Start and Application_End methods)
'The object myrat is defined as public (utility.cs):
public static DataTools_DtRat.DtxClass myRat = new DataTools_DtRat.DtxClass();
'Application_Start command (in the Global.asax file) calls the StartRAT function below:
public static void openRat() {
myRat.DtxOpen(); }
'Application_End command (in the Global.asax file) calls the EndRAT function below:
public static void closeRat() {
myRat.DtxClose(); }
'The GetAddressInfo function can be called many times by various users:
[WebMethod]
public string GetAddressInfo(string addressline, string localityline) { string mystrcol; bool mystat; long lngProcessID; try { lngProcessID = utility.myRat.DtxCreateProcess(); int myres;
Object objPID = (Object)lngProcessID.ToString(); Object objAdd = (Object)addressline;
Object objLoc = (Object)localityline;
Object objConstAddLine = (Object)(String.Copy("Address_Line")); Object objConstLoc = (Object)(String.Copy("Locality"));
Object objConstState = (Object)(String.Copy("State")); Object objConstPostcode= (Object)(String.Copy("Postcode")); int one = 1;
- 95 -
myres = utility.myRat.DtxSearchAddressLineAMAS(ref objPID, ref objAdd, ref objLoc); mystrcol = myres.ToString();
mystrcol += "*"+utility.myRat.DtxExtractResultField(ref objPID, ref objConstAddLine,ref objConstOne); mystrcol += "*"+utility.myRat.DtxExtractResultField(ref objPID, ref objConstLoc,ref objConstOne); mystrcol += "*"+utility.myRat.DtxExtractResultField(ref objPID, ref objConstState,ref objConstOne); mystrcol += "*"+utility.myRat.DtxExtractResultField(ref objPID, ref objConstPostcode,ref objConstOne); utility.myRat.DtxDisposeOfProcess(ref objPID); return mystrcol; } catch (Exception e) { return e.Message; } }
- 96 -
Client Side VB Script Example
Sample Description
The following HTML and client side VB script can be used to create a web page to allow address validation using the RAT API. Simply copy and paste the coding below into a text file or use a HTML editor.
Note: You will have set the security setting of "Initialize and script ActiveX controls not marked as safe" for Internet Explorer to 'prompt' or 'enabled' to make this example work. This setting is set by default on Internet Explorer 4 service pack 1 and later versions to 'disabled' causing the follow error to appear "ActiveX component can't create object: 'createobject' ".