Create DLL in VB.Net
How to create DLL in VB.Net, using this simple line of code, you may understand what is the function of DLL in VB.Net and how it works. The purposed of this, once you have a DLL, you can call anytime your procedure if needed by adding reference in your project where your folder name DLL saves. DLL stand for Dynamic Link Library, a collection of subroutines stored on disk, which can be loaded into memory and executed when accessed by a running program.
Here are the steps
1. Start Visual Basic, instead of windows form appear in your window, click Class Library and name it MyClassLibrary.
2. Copy and Paste this code in your Class1
Public Class Class1Public Function Add(ByVal Num1 As Integer, ByVal Num2 As Integer)Dim result As Integerresult = Num1 + Num2Return resultEnd Function
Public Function Subtraction(ByVal Num1 As Integer, ByVal Num2 As Integer)Dim result As Integerresult = Num1 - Num2Return resultEnd Function
Public Function Multiplication(ByVal Num1 As Integer, ByVal Num2 As Integer)Dim result As Integerresult = Num1 * Num2Return resultEnd Function
Public Function Division(ByVal Num1 As Integer, ByVal Num2 As Integer)Dim result As Integerresult = Num1 / Num2Return resultEnd FunctionEnd Class
3. Finally, Click Save All, make sure you save properly where you folder is located, because you can call anytime if needed in your project.
4. Click Build MyClassLibrary
5. Now, we’re already created DLL.
6. Close your program.
The above code simply created to show you on how to create simple DLL in your project. You can create complex DLL code if you can manage the function of its control or you can download through internet and modify the code.
7. Open Visual Basic and create new project, name it My Simple DLL, add 2 textbox and 1 button. Name your textbox1 as txtnum1 and textbox2 as txtnum2, and button1 as btncalculate.
8. Now, we are going to add our DLL we’re already created to our project.
9. In your solution explorer, double click My Project --> References --> Add --> and click Browse tab OR click Project between Build and View, locate Add Reference and click browse tab, and locate you folder where you DLL saves you’ve already created.
10. <your folder name> --> bin --> Release --> <MyClassLibrary.dll>
11. Finally, you’ve already add MyClassLibrary.dll in your project.
12. Copy and Paste this code on your btncalculate.
Imports MyClassLibrary
Public Class Form1
Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalculate.ClickDim x As New Class1Dim HoldMyData As Integer
HoldMyData = x.Add(txtnum1.Text, txtnum2.Text)MessageBox.Show(HoldMyData)
End SubEnd Class
Hope this very helpful…