Previous | Home | Next |
A dynamic linking library (DLL) is linked to your program at run time. DLL is similar to an EXE but is not directly executable. Functions in the dll are called from the main exe. It provides a way to split what would be a very large exe into an exe plus one or more dlls.
Creating DLL in VB.Net
To creating DLL in VB.Net just follow next steps-
Goto File -> New Project then choose Class Library you will see window like below.
Here i am going to show DLL for addition, subtraction, multiplication, and division. Code for this is given below
Public Class Class1 Public Function add(ByVal x As Integer, ByVal y As Integer) As Integer Dim z As Integer = x + y Return z End Function Public Function [sub](ByVal x As Integer, ByVal y As Integer) As Integer Dim z As Integer = x - y Return z End Function Public Function mul(ByVal x As Integer, ByVal y As Integer) As Integer Dim z As Integer = x * y Return z End Function Public Function div(ByVal x As Integer, ByVal y As Integer) As Integer Dim z As Integer = x \ y Return z End Function End Class
After this Build this class by pressing F6 and dll will generate this class library now you can use this in any other application where you want to use this dll.
Using DLL in VB.Net Application
For using DLL in application you have to make add reference of the dll that you
Design the form as shown in below picture
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim c1 As ClassLibrary1.Class1 = New Class1() Dim result As Integer = c1.add(Integer.Parse(textBox1.Text), Integer.Parse(textBox2.Text)) textBox3.Text = result.ToString() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim c2 As ClassLibrary1.Class1 = New Class1() Dim result As Integer = c2.[sub](Integer.Parse(textBox1.Text), Integer.Parse(textBox2.Text)) textBox3.Text = result.ToString() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim c3 As ClassLibrary1.Class1 = New Class1() Dim result As Integer = c3.mul(Integer.Parse(textBox1.Text), Integer.Parse(textBox2.Text)) textBox3.Text = result.ToString() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim c4 As ClassLibrary1.Class1 = New Class1() Dim result As Integer = c4.div(Integer.Parse(textBox1.Text), Integer.Parse(textBox2.Text)) textBox3.Text = result.ToString() End Sub
Previous | Home | Next |