Using the CountryHawk component

To use the CountryHawk component from your application or web script you simply create an instance of the component from the programming language your application is running in. The method used to create an instance of the object depends on what language you are writing your application or web site in.

This following code snippets demonstrate how to create an instance of CountryHawk using ASP, ASP.NET, Visual Basic, and ColdFusion and display its associated country code:

Example 1: Creating an instance using ASP (ActiveX/COM)

<% set chObj = Server.CreateObject("cyScape.CountryObj")

response.write "Your country is " & chObj.CountryCode %>

Example 2: Creating an instance using ASP.NET (.NET version using VB.NET)

<%@ Import Namespace="cyScape.CountryHawk" %>

<% CountryObj chObj = CountryObj.GetCountry()

Response.Write("Your country is " + chObj.CountryCode) %>

Note: The "new" keyword is not used in conjunction with the CountryObj class. Instead use the static GetCountry() method as shown above to get the country information.

Example 3: Creating an instance using ASP.NET (.NET version using C#)

<%@ Import Namespace="cyScape.CountryHawk" %>

<% CountryObj chObj = CountryObj.GetCountry();

Response.Write("Your country is " + chObj.CountryCode); %>

Note: The "new" keyword is not used in conjunction with the CountryObj class. Instead use the static GetCountry() method as shown above to get the country information.

Example 4: Creating an instance using Visual Basic (ActiveX/COM)

Dim chObj as Object

set chObj = CreateObject("cyScape.countryObj")

chObj.Initialize "207.46.230.220"

msgbox "Country for IP 207.46.230.220 is: " & chObj.CountryCode

Example 5: Creating an instance using ColdFusion (ActiveX/COM)

<CFOBJECT ACTION="CREATE" NAME="chObj" CLASS="cyScape.countryObj">

<CFSET chObj.Initialize("#CGI.REMOTE_ADDR#")>

<CFOUTPUT> Your country is #chObj.CountryCode# </CFOUTPUT>

Tip: See the section on Using the <CF_CountryHawk> Custom Tag for more information on using CountryHawk with ColdFusion.

See the Properties and Methods Guide for details on the various properties and method of the component you can call once you create an instance of it as shown above.

Tip: See the sample scripts for working examples that demonstrate many common uses of CountryHawk. These scripts are well commented and serve as excellent learning material.

Note: CountryHawk4J is a JavaBean that provides a full implementation of CountryHawk for use with Java environments, such as JSP and servlets. For usage information in those environments please consult the CountryHawk4J documentation.

See Also:

About the CountryHawk Users Guide

Understanding and customizing the data files

Defining Regions

Updating the data files

Properties and Methods Guide

About the sample scripts

Using the <CF_CountryHawk> Custom Tag