Creating a Class Library
--------------------------------------------------------------------------------

1) Choose File NewProject
2) Select ClassLibrary from the project templetes.
3) Suppose I rename it to ClassLibrary.
4) Add Code inside the block code.
I write
Public Class assembly
Public Function add(ByVal x As Integer, ByVal y As Integer)
Return x + y
End Function
End Class
5) Choose Build-Build ClassLibrary.


RUNNING A DLL FILE—
1)Project-->Add WindowsFormRename it to Yogesh
2) Server Explorer-->Right Click-->Add Reference-->Open the ClassLibrary.
3)Imports Assembly
In the above imports statement, Imports assembly is there or
Imports ClassLibrary is there.

Public Class yogesh
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

End Sub
End Class
I also do not know what to write on the click event of the button.

>I also do not know what to write on the click event of the button.
It's kind of hard to tell you what to write when I have no idea what you want the form to do. :icon_rolleyes:

adding a function to DLL or Class Libary- Means that one we add the function in DLL,we can call this function on any form.
I want simple addtion function & this fn. can be called on any form by.

Hi Damy Ur Syntax is wrong,
dim obj as new classLibrary.assembly

Let's say it again

1- Right click on the project you want to add the dll to.
2- Add reference then browse your dll
3- In the .cs file you call Add method, imports the class library i.e import [ClassLibraryName]
4- Initiate a object from Add method class then call its add method.

hint: dll is the class library output

I think that's tooo clear to solve your problem or I didn't understand you well.

Public Class assembly
Public Function add(ByVal x As Integer, ByVal y As Integer)
Return x + y
End Function
End Class


Calling Method--Imports ClassLibrary
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj As New ClassLibrary.assembly
Dim sum As Integer
sum=obj.
End Sub
End Class

Now this is the coding i m writing,See & reply

First Error due to the foll. line--
Dim obj As New ClassLibrary.assembly
Error-'assembly' is ambiguous in the namespace 'ClassLibrary'.

Second Error
sum=obj.
After ., add is not coming automatically.

First Error due to the foll. line--
Dim obj As New ClassLibrary.assembly
Error-'assembly' is ambiguous in the namespace 'ClassLibrary'.

Second Error
sum=obj.
After ., add is not coming automatically.

hi guy this is my test with VB.NET 2005,
this output is 30 and you can use it all forms
and I don't add anythink

Public Class Yogesh
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj As New assembly
MsgBox(obj.add(10, 20))
End Sub
End Class

First of all never use keywords like classlibrary or assembly Specify it like classlibrary1 or asembly1 .

Second thing you have written the function

Public Function add(ByVal x As Integer, ByVal y As Integer)
Return x + y
End Function

change it to

Public Function add(ByVal x As Integer, ByVal y As Integer) as integer
Return x + y
End Function

as it is a return type function u are returning some of the values so mention the return type

Third thing you have asked that classlibrary will come or assembly will come

Both are right
Basically classlibrary1 will be the name of the dll and assembly1 will be the name of the class

so if you use classlibrary1 then u will have to create the object of the assembly1

or
if u use import claslibrary1.assembly1
then you can call all the public function defined in the assembly1


Next the process of adding the dll is quite right
you want that the function of the class should be called in any of the form and what exactly we have to write in button click
When u are defining the parameter in the function you have to supply the parameter values

Study the given code

dll file code
Public Class assembly1
Public Function add(ByVal x As Integer, ByVal y As Integer) As Integer
Return x + y
End Function
End Class

Form code considering three textbox and one command button

Imports ClassLibrary2

Public Class Form1
Dim c As New assembly1 'create object of class


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox3.Text = c.add(CInt(TextBox1.Text), CInt(TextBox2.Text))


End Sub
End Class


Hope it will solve your problem

This article has been dead for over six months. Start a new discussion instead.