What's New
Q & A
Tip Jar
C# Helper...
Follow VBHelper on Twitter
MSDN Visual Basic Community
TitleUse a .NET system DLL in a Visual Basic 6 program
DescriptionThis example shows how to use a .NET system DLL in a Visual Basic 6 program.
KeywordsVB .NET, DLL, VB .NET, System DLL, WebClient, downloadFile
CategoriesSoftware Engineering, Windows, VB.NET, Miscellany
For more details, see the article Calling .Net Classes from Visual Basic 6 by Peter Aitken.

This example contains a VB 6 program that uses the .NET System namespace. The steps to prepare the example are:

  1. Register the system.dll assembly created by the .NET Framework as a COM object:
      Open a DOS command window. Type: CD C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 Type: regasm system.dll
  2. Add a reference to the DLL.
    1. Create a Visual Basic project.
    2. Select the Project menu's References command.
    3. In the References dialog, click Browse.
    4. Navigate to C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322. Select the system.tlb file and click Open.
      *** Important *** Select the ".tlb" file not the ".dll" file.
      The ".tlb" file contains extra information that Visual Basic needs to use the DLL.
    5. Click OK to close the References dialog.
  3. Use the DLL in the VB project (see below).

When the program starts, the Form_Load event handler creates a new System.WebClient object from the .NET System DLL. It uses that object's downloadFile method to copy a file from the Internet to a local file. It then loads the picture and displays it.

Private Sub Form_Load()
Dim wc As System.WebClient

    ' Create a WebClient.
    Set wc = New System.WebClient

    ' Download a picture file.
    wc.downloadFile _
        "http://www.vb-helper.com/vb_prog_ref.jpg", _
        App.Path & "\vb_prog_ref.jpg"

    ' Display the image.
    Set Image1.Picture = LoadPicture(App.Path & _

    ' Size the form to fit.
    Me.Width = 2 * Image1.Left + Image1.Width + Me.Width - _
    Me.Height = 2 * Image1.Top + Image1.Height + Me.Height _
        - Me.ScaleHeight
End Sub
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.