News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

Use a .NET system DLL in a Visual Basic 6 program

Started by dhilipkumar, Nov 21, 2008, 07:55 PM

Previous topic - Next topic

dhilipkumar

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:

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
Add a reference to the DLL.
Create a Visual Basic project.
Select the Project menu's References command.
In the References dialog, click Browse.
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.
Click OK to close the References dialog.
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 & _
        "\vb_prog_ref.jpg")

    ' Size the form to fit.
    Me.Width = 2 * Image1.Left + Image1.Width + Me.Width - _
        Me.ScaleWidth
    Me.Height = 2 * Image1.Top + Image1.Height + Me.Height _
        - Me.ScaleHeight
End Sub