|
-
Mar 31st, 2006, 04:08 PM
#1
Thread Starter
Hyperactive Member
Create code that can be used in multiple projects (dll?) (Resolved)
What is the process for making a function into a dll(?) that can be used in multiple projects? Let me use the extremely simple function as an example.
VB Code:
Public Function DoCalcs( _
ByVal a As Double, _
ByVal b As Double, _
ByVal c As Double, _
ByVal d As Double) As Double
Dim myCalc As Double = (a * b / c - d)
Return myCalc
End Function
How would I make it so that I can add this function to any project using a reference (or whatever)?
Last edited by FastEddie; Mar 31st, 2006 at 05:02 PM.
-
Mar 31st, 2006, 04:18 PM
#2
Re: Create code that can be used in multiple projects (dll?)
you simply change the output to class library (Right click project, go to properties, change "output type" to class library). When it compiles, it creates a dll, which you can just reference. I think the default namespace would be the name of the assembly, although you can create a namespace using the "namespace" keyword...
-
Mar 31st, 2006, 04:24 PM
#3
Thread Starter
Hyperactive Member
Re: Create code that can be used in multiple projects (dll?)
you simply change the output to class library (Right click project, go to properties, change "output type" to class library). When it compiles, it creates a dll, which you can just reference.
That is what I thought so I must be doing something else wrong. Should the function be stored in a class file or a module (or something else)?
Also, once done, all I need to do is to add that created dll as a reference correct?
-
Mar 31st, 2006, 04:27 PM
#4
Re: Create code that can be used in multiple projects (dll?)
Not sure how modules would work with it, as I have only made class libraries out of full class files. All you would have to do is add a new class to whatever you are doing this in, and name the class what you want, put the function code in there (along with any other functions you want to use), then build it. Then its a matter of referencing the dll, declaring a new instance of the class that contains the function, then using the function.
-
Mar 31st, 2006, 04:41 PM
#5
Thread Starter
Hyperactive Member
Re: Create code that can be used in multiple projects (dll?)
Ok I almost have it. My Class is named doACalc and the function is DoCalcs and the code block that I want to use it looks like this
VB Code:
Dim d1 As Double = CDbl(tb1.Text)
Dim d2 As Double = CDbl(tb2.Text)
Dim d3 As Double = CDbl(tb3.Text)
Dim d4 As Double = CDbl(tb4.Text)
Dim Answer As String = DoCalcs(d1, d2, d3, d4).ToString
Label1.Text = Answer
What is the proper way to get the new instance in this block?
-
Mar 31st, 2006, 04:48 PM
#6
Re: Create code that can be used in multiple projects (dll?)
a form is a class, so how would you go about declaring a new instance of a form? Its the same way. Since you are referencing this dll (remember to add a reference to the dll in your project), you just use the namespace to navigate to that class in intellisense...
VB Code:
'replace "MyAssemblyNamespace" assembly name of your dll, or the namespace you defined in the class...
Dim MyNewClass as New MyAssemblyNamespace.doACalc
MyNewClass.Docalcs()
You may not even have to declare a new instance of the class, you might be able to get away with just "MyAssemblyNamespace.doACalc.Docalcs()", but I am not positive...
Last edited by gigemboy; Mar 31st, 2006 at 04:51 PM.
-
Mar 31st, 2006, 05:02 PM
#7
Thread Starter
Hyperactive Member
Re: Create code that can be used in multiple projects (dll?)
Thanks Gig. For those of you following along this is how it ended up looking.
VB Code:
Dim d1 As Double = CDbl(tb1.Text)
Dim d2 As Double = CDbl(tb2.Text)
Dim d3 As Double = CDbl(tb3.Text)
Dim d4 As Double = CDbl(tb4.Text)
Dim MyNewClass As New DoCalcs.Buck.doAcalc
Label1.Text = MyNewClass.DoCalcs(d1, d2, d3, d4).ToString
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|