Search:
Namespaces
Discussions
.NET v1.1
Feedback
How to create a dll and call it (VB .net)
Messages
Related Types
This message was discovered on
microsoft.public.vsnet.general
.
Post a new message to this list...
Todd Tuskey
(I don't think this falls under the type of dll you have to run regsvr32.exe
with, I may be wrong)
Below is a very simple application, just to see if I can do this.
What I want to do is put the two functions, TimesTwo and TimesThree in one
common callable component (a .dll I suppose).
I've created a dll (at least the build went ok) containing those two
functions enclosed in a CLASS, but can't figure out how to call it.
Thanks!
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.
Object
, ByVal e As
System.EventArgs) Handles Button1.Click
MsgBox(TimesTwo(12) & "/" & TimesThree(12))
End Sub
Public Function TimesTwo(ByVal numIn As Integer) As Integer
TimesTwo = numIn * 2
End Function
Public Function TimesThree(ByVal numIn As Integer) As Integer
TimesThree = numIn * 3
End Function
End Class
Reply to this message...
Scott M.
If you want to call this class from another class within the same
application:
Create a new form or module and in that code add:
Dim x as new Form1
Now, you can access those functions you wrote into the first class as
methods of x.
x.TimesTwo
x.TimesThree
If you need to access these functions from a different application, you will
need to make a reference to the first assembly. After the reference is made
you do almost the same as above but to create the class instance you will
need to qualify its root namespace (usually the same as the project name).
Dim x as new AssemblyRootNamespace.Form1
x.TimesTwo
x.TimesThree
"Todd Tuskey" <
Click here to reveal e-mail address
> wrote in message
news:2Z9Yc.520$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Todd Tuskey
Thanks Scott, I'll try that also. Similar to how I got it to work just now:
I got it to run, but is this "the" way to get your dlls to work?
I compiled the DLL as a class.
Then I imported the class into my project (project->add reference).
Then I set an variable equal to a new instance of my class. I could then
accesss all of the functions with the syntax form x =
ClassVariable.ClassFunction(x,y)
"Scott M." <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Scott M.
You did what I indicated with the exception of what you are setting your
variable to. Why would you set a variable equal to a function call when
just making an instance of the class allows you access to all the members of
the class?
"Todd Tuskey" <
Click here to reveal e-mail address
> wrote in message
news:41dYc.525$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Todd Tuskey
Because the compiler told me that in order to reference any of the functions
I need to have an instance of its class.
(I think we're saying the same thing, just two different ways).
So for example if I had a function to add one to a number it would be
referenced like this:
Dim Fn as new MyFunctions.MathFuncions()
(All functions are now available through the class variable Fn.
Then I'd call it like:
MsgBox(Fn.AddOne(x))
"Scott M." <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Scott M.
Well not exactly:
Dim Fn as new MyFunctions.MathFuncions()
Is an instance of the class function, so the function could now be called
as: Fn(), not its original name MathFunctions()
Dim Fn as new MyFunctions is an instance of the class, so the function would
now be called as: Fn.MathFunctions()
When you do it the first way, you don't have access to any other members of
the class (your way Fn only refers to the class function:
"MathFunctions()"). When you do it as I have shown, you can use Fn (the
instance of the class) to get at all members of the class:
Fn.Function1()
Fn.Function2()
Fn.ClassProperty
Fn.Field
etc.
See the difference?
"Todd Tuskey" <
Click here to reveal e-mail address
> wrote in message
news:4jeYc.526$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Todd
Exactly. That's what I'm doing.
Here's the exact code (RexxUtilities is the actuall dll for which I included
a reference. WordUtilities is the class).
All three functions in this class are are accessible in my calling program
below).
Public Rx As New RexxUtilities.WordUtilities ' Rx is instance of
WordUtilities class
...
...
Dim TestString As String = "This is a test string to demonstrate word
functions"
MsgBox("The number of words in '" & TestString & "' is " &
Rx.Words(TestString))
MsgBox("The third word of '" & TestString & "' is '" & Rx.Word(TestString,
3) & "'")
MsgBox("SubWord(3,2) of '" & TestString & "' is '" & Rx.SubWord(TestString,
3, 2) & "'")
Thanks for all of your help, Scott.
"Scott M." <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Scott M.
Yep, it looks good!
"Todd" <
Click here to reveal e-mail address
> wrote in message
news:KfsYc.531$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
System.EventArgs
System.Object
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com