Using the RegionStats Object

The RegionStats object is similar to the CountryStats object, except it is used to provide statistics on the total number of hits by region instead of by country.

ActiveX/COM: You create an instance of the CountryStats object by specifying the class ID string of "cyScape.RegionStats" in your call to CreateObject. Once you have this object, you can request stats for a particular country, or stats for all countries using "FOR EACH / NEXT" syntax.

Native .NET: You create an instance of the RegionStats object by declaring a variable of type RegionStats and setting it to "new RegionStats()". Once you have this object, you can request stats for each region using enumeration with the "foreach" statement.

Each time you process a lookup with the CountryHawk object, CountryHawk automatically increments the internal hit count for the matching region by 1. You use the RegionStats object to access these internal counts.

Tip: By default CountryHawk keeps the statistics in memory only, so the statistics are cleared each time you restart your web services or applications that use CountryHawk. However, you can use the PersistToFile and LoadFromFile methods of the CountryStats object to persist the region statistics and keep running totals on an ongoing basis!

See the RegionStats Object Properties and Methods for details on all properties and methods supported by this object.

ActiveX/COM Examples:

Example - Obtaining total hits for a particular region:

set statsObj = CreateObject("cyScape.RegionStats")

regionHits = statsObj.Total("westerneurpoe")

response.write "Total hits for Western Europe: " & regionHits

Example - Obtaining total hits for all regions from most to least hits:

set regStatsObj = CreateObject("cyScape.CountryStats")

foreach country in regStatsObj

regionName = regStatsObj.RegionName(regionCode)

hitsForThisRegion = regStatsObj.Total(regionCode)

response.write regionName & ": " & hitsForThisRegion & "<br>"

next

Tip: Total is the default property for the RegionStats object. Therefore if you can use regStatsObj(regionCode) instead of regStatsObj.Total(regionCode) if you prefer.

.NET Examples:

Example - Obtaining total hits for a particular region code (VB.NET):

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

dim regObj as RegionObj = RegionObj.GetRegion("northamerica")

Response.Write("Total hits for North America are: " + regObj.HitCount.ToString())

Example - Obtaining total hits for the region associated with a particular country (C#):

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

CountryObj chObj = CountryObj.GetCountry();

RegionObj regObj = RegionObj.GetRegion(chObj);

Response.Write("Total hits for your region is: " + regObj.HitCount.ToString());

Example - Obtaining total hits for all regions - most to least hits (C#):

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

RegionStats regStats = new RegionStats();

foreach (RegionObj regObj in regStats)

{

 Response.Write(regObj.RegionCode + " " + regObj.RegionName: " + regObj.HitCount.ToString());

}

Note: Use of the RegionStats object and its properties and methods requires the Enterprise Edition of CountryHawk.