Contact Info

Crumbtrail » Network Component » How to Use Network Component » IP to Country » Visual Basic 6

How to use IPtoCountry in a Visual Basic project

Network Component provides an easy-to-use development interface to a variety of IP protocols. By using Network Component, you can very easily create or enhance applications with network features.

Network Component features the following: DNS, FTP, HTTP, HTTPs, ICMP Ping, IP-to-Country, MSN, NTP, RSH, SCP, SFTP, SNMP v1/v2c (Get, GetNext, Set), SNMP Traps, SNMP MIB, SSH, TCP, Telnet, TFTP, UDP, Telnet, Wake-On-LAN and more.

Network Component can be well integrated into any development platform that supports ActiveX objects.

Step 1: Download and install the Network Component

Download Network Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new Visual Basic project

Launch 'Microsoft Visual Basic' from the Start menu, and choose 'New' from the 'File Menu'. The 'New Project' dialog appears.
Select 'Standard Exe' and click 'OK':

Visual Basic

(Click on the picture to enlarge)

Step 3: Refer to the Network Component Library and create the objects

A new Project is created, with a blank form.

First, you must add a reference to Network Component in the project to be able to use the object. To do so, choose 'References...' from the 'Project' menu. In the 'References' dialog that pops up, enable the 'Network Component 3.1 Type Library' reference as shown in the following picture:

(Click on the picture to enlarge)

Click 'OK' to close the 'References...' dialog.

Then, select the Project form and choose 'View Code' from the context menu:

(Click on the picture to enlarge)

On top of your code, declare the following object:

Public objIPtoCountry As AxNetwork.IPtoCountry

Step 4: Create the object

From the Code window, select 'Form'. The Private Sub 'Form_Load()' will be displayed now. In the 'Form Load' function, create the object in the following way:

Set objIPtoCountry = CreateObject("AxNetwork.IPtoCountry")

Appendix: Full source code

<object runat="server" progid="AxNetwork.IPtoCountry" id="objIPtoCountry"> </object>

' HTML-CSS layout includes below, no code there!
<!-- #include file="css/Header.html" -->
<!-- #include file="css/Menu.html" -->

  ' A license key is required to unlock this component after the trial period has expired.
  ' Call 'Activate' with a valid license key as its first parameter. Second parameter determines whether to save the license key permanently 
  ' to the registry (True, so you need to call Activate only once), or not to store the key permanently (False, so you need to call Activate
  ' every time the component is created). For details, see manual, chapter "Product Activation".
  ' objDnsServer.Activate "XXXXX-XXXXX-XXXXX", False    

  Dim numLastError, strLastError, strResCountryCode, strResCountryCodeEx, strResCountryName

  Set fso = CreateObject("Scripting.FileSystemObject")
  strLogfile = fso.GetSpecialFolder(2) & "\IpToCountry.log"
  strLastError                = ""
  strResCountryCode           = ""
  strResCountryCodeEx         = ""
  strResCountryName           = ""

  If( Request( "txtSubmit" ) <> "" ) Then

    objIPtoCountry.LogFile   = Request( "txtLogFile" )   ' Optional: set LogFile property for troubleshooting purposes

    objIPtoCountry.Host      = Request( "txtHost" )
    numLastError             =  objIPtoCountry.LastError
    strLastError             =  numLastError & ": " & objIPtoCountry.GetErrorDescription( numLastError )  
    If numLastError = 0 Then
       strResCountryCode     = objIPtoCountry.CountryCode
       strResCountryCodeEx   = objIPtoCountry.CountryCodeEx
       strResCountryName     = objIPtoCountry.CountryName
    End If
  End If

  <h1>ActiveXperts Network Component ASP Sample - IP to Country</h1>
  <form action="iptocountry.asp" method="post">
    <h3>Module [<% = objIPtoCountry.Module %>]; Build [<% = objIPtoCountry.Build %>]</h3>
    <!-- Host -->
    <label for="host">Host:</label>
      <input type="text" name="txtHost" value=<% If Request( "txtHost" ) = "" Then %>""<% Else %><% = Request( "txtHost" ) %><% End If %>>
    <!-- Submit Button -->
      <input type="submit" value="Query" name="txtSubmit">
    <!-- Clear Row -->

    <!-- Logfile -->
    <label for="Logfile">Logfile:</label>
      <input type="text" id="LogFile" name="txtLogFile" value="<% = strLogfile %>" />
    <!-- Result code -->
    <label for="Result">Result code:</label>
      <input type="text" id="Result" name="txtResult" style="font-weight: bold;" value="<% = strLastError %>" />
    <!-- Country Code -->
    <label for="CountryCode">Country Code:</label>
      <input type="text" name="txtCountryCode" value="<% = strResCountryCode %>" />
    <!-- Country Code Ex -->
    <label for="CountryCodeEx">Country Code Ex:</label>
      <input type="text" name="txtCountryCodeEX" value="<% = strResCountryCodeEx %>" />
    <!-- CountryName -->
    <label for="CountryName">Country Name:</label>
      <input type="text" name="txtCountryName" value="<% = strResCountryName %>" />
    <br />
    <br />    
    This sample is based on ActiveXperts Network Component, an <a href="" target="_blank">ActiveXperts Software</a> product.<br />
    <a href="Default.asp">Back to main page</a>
</div><!-- /container -->
' HTML-CSS layout include below, no code there!
<!-- #include file="css/Footer.html" -->

You can download the complete sample on our FTP site There are many other working Network Component scripts on our site and shipped with the product.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The Network Component project ships with a set of Microsoft Visual Studio .NET samples, including samples for Microsoft Visual C# .NET. The projects are created with Microsoft Visual Studio 2008.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.