Using the Inet Control

Adding Functionality

First of all, we are going to add some properties to the class module. You can use class builder utility for this purpose. Add the following properties to the class:

Private mstrStatus As String 'local copy
Private mvarProxyAddress As String 'local copy
Private mvarRemotePort1 As String 'local copy
Private mvarRemoteHost1 As String 'local copy

(Note you need to associate each of those properties with the properties of the Inet control using the class builder utility, rather than just copying the code above). Lets discuss these properties one by one. The first property will be used to display the status of the file transfer. The following messages are displayed:

  • URL not provided
    This message is displayed if the correct URL is not provided or is not provided at all.
  • Timed Out
    This message is displayed when the time out occurs.
  • Server not found
    If the computer from where the file is to be downloaded is not found then this error message is displayed.
  • File not found
    If the file is not found on the remote computer then this message will tell the user that the file could not be found.
  • File was downloaded successfully
    This message is displayed if the file is successfully retrieved and downloaded to the system.

The second property is used to get proxy address from the user. This property is used to set or get the name of the proxy server used to access the Internet.

The third property will be used to connect to the remote port of the server. This property is used to set or get the port number of the remote system to which the control connects.

The fourth property is used to access the remote host. This property is used to set or get the address of the remote system to which the control sends and/or receives data.

Now lets move on to the main function. Declare the function as below:

Public Function DLoad(ByVal strURL As String, Optional ByVal sOutPutFile As String)

Two parameters are passed to the function, the first one is the string containing the address of the file to be downloaded and the second parameter is the string containing the name and path of the output file to be generated. File handling routine is not included in this component, this will have to be incorporated in the ASP script or the VB application, which ever is used as a test driver.

Next, declare variables that will be used through out the class module, these are following:

Dim bytes() As Byte
Dim fn As Integer
Dim msg As String
Dim buf As String
Dim fnf As Integer
Dim snf As Integer
Dim tout As Integer
Dim OK As Integer
Dim tempbuf As String
Dim strResult As String

Bytes() is the array of bytes which will contain the downloaded material. "fn" will contain the number of the file which will be opened to be written to. Other important variables include "buf", "fnf", "snf" and "tout". "buf" is a buffer which will contain the data. "fnf" stands for "file not found" and will contain the number of files not found. "snf" stands for "server not found" and will contain the number of remote addresses not found. "tout" stands for "timed out" and will contain the number of timed out messages. "strResult" will contain the downloaded string.

Next, set the properties to default values if no values are provided by the user.

With Form1.Inet1
    'Set the transfer protocol
    .Protocol = icHTTP

    'Set the Access Type to Default
    .AccessType = icUseDefault

    'Set the proxy address
    If Not ProxyAddress = "" Then
        .Proxy = ProxyAddress
    End If

    If Not RemotePort1 = "" Then
        .RemotePort = RemotePort1
    End If
End With

Notice the way we are accessing the control's properties. We set the protocol to HTTP. HTTP protocol is a stateless protocol. Originally, HTTP was designed for the transmission of text but it can be used to transfer binary files as well. Next, we set the AccessType property to default. AccessType specifies how the control will access the Internet. There are three possible settings for this property:

  • icUseDefault
    The control uses the access settings that are specified in the Windows registry to access the Internet.
  • icDirect
    The control has a direct connection to the Internet.
  • icNamedProxy
    The control uses a proxy server. The proxy server must be specified in the control's Proxy property.

Similarly, set the remotehost and remoteport property which are supplied by the user.

You might also like...


About the author

S.S. Ahmed United States

S.S. Ahmed is a senior IT Professional and works for a web and software development firm. Ahmed is a Microsoft Office SharePoint Server MVP. Ahmed specializes in creating database driven dynamic...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“We better hurry up and start coding, there are going to be a lot of bugs to fix.”