Last month, August 2003, I published a tip that uses a Class Library [DLL] to update an application's database using a model database's schema. This month I describe the process used to reference a Class Library in a VB .Net Windows Application. The steps in the process:
- Create the Class Library Code - write the code used in the DLL.
- Add a project to the solution to test the Class Library - optional.
- Build the Class Library - DLL.
- Create a new or open an existing VB .Net Windows Application.
- Reference the Class Library.
- Begin using the properties and methods of the Class Library.
I created a simple VB .Net Windows Application to test a Class Library, the demo:
Demo Application - sets the name property and gets the current date.
Code used in the demo application.
In form load, call subroutine UseMyClass which defines a reference to the class,
sets property 'MyName' to Larry Rebich, loads 'MyName' into the first text box and
uses method 'GetDate' to insert the current date into the second text box.
Sample Class Library Code
A reference needs to be added to a Windows Application if the properties and methods of the Class Library are to be used. The process:
Right mouse click on Solution Explorer 'References' and select 'Add Reference'.
Select the Add Reference dialog Projects tab then click the Browse button.
Browse for the class library: 'MyClassLibrary' then click Open.
Note that 'MyClassLibrary' is added as a reference in the application.
And it is copied to the project's bin folder.
The reference appears in the Solution Explorer.
You can now begin to use properties and methods from the class library.
Download VB Code
Click here to download the VB.Net Source Code [32k]. The source code contains two VB .Net solutions - the class library and the demo program.
Previous Tip Tip Index Next Tip