Click to See Complete Forum and Search --> : How to call a function of a class library?
PT Exorcist
Aug 1st, 2002, 02:15 PM
how do i call a function of a class library in vb.net?
Edneeis
Aug 1st, 2002, 04:32 PM
Make on object of one of the classes and then call the function you want.
Matt02
Aug 1st, 2002, 05:34 PM
Unless the function is declared as 'shared' then you don't need an object instance
PT Exorcist
Aug 1st, 2002, 05:55 PM
how do i do that ( i want code plz ) tks
Matt02
Aug 1st, 2002, 06:02 PM
In your class library where you have
Public Sub SomeFunction(ByVal somevar As String)
just change it to
Public Shared Sub SomeFunction(ByVal somevar As String)
PT Exorcist
Aug 1st, 2002, 06:20 PM
but how do i call it? the topic says how to call not how to make it...:eek:
Matt02
Aug 1st, 2002, 06:27 PM
Edneeis answered that earlier, but if you need the actual syntax
<project name>.<class name>.<funtion name>
eg.
projectname.myclass.myfunction(myargs)
unless you import projectname.myclass in which case you could just use myfunction(myargs) and if the class is in the same project as you are calling it from then you can leave off the project name.
Does that make it clear?:confused:
PT Exorcist
Aug 1st, 2002, 06:37 PM
C:\Documents and Settings\JBRANCO\My Documents\Visual Studio Projects\WindowsApplication27\Form1.vb(47): Name 'classlibrary2' is not declared.
...
PT Exorcist
Aug 1st, 2002, 06:43 PM
let me explain that i want that an EXE file calls a DLL's file so , it must connect to another file
Edneeis
Aug 1st, 2002, 07:19 PM
Did you add a reference to it?
You still have to add references in .NET although it isn't reliant on the registry as much.
PT Exorcist
Aug 1st, 2002, 07:32 PM
do i really have to do that? what if i want my prog to dinamicly add them at run-time..?
PT Exorcist
Aug 1st, 2002, 07:32 PM
my idea was to load all the "plugins" that are in the /plugin/ directory....
Edneeis
Aug 1st, 2002, 08:43 PM
I'm not positive but I believe you can still use CreateObject. One good thing about .NET is you don't have to register the plugins before you use them.
PT Exorcist
Aug 2nd, 2002, 07:17 AM
i tryed old way but it seems not to work , or at least not the same way:
[Highlight=VB]
dim LOL as object
LOL = CreateObject("project2.class1")
LOL.Test(arg1,arg2)
[Highlight=VB]
also tryed with Set LOL but it seems not to work too
DevGrp
Aug 2nd, 2002, 08:46 AM
Dude you have to add a reference to the class library and you aslo have to declare an instance of the class you want to use explicitly. If the class is shared then it does not have to be instantiated.
Now if you want to load a library, you have check out the System.Reflection namespace. Another thing check out the System.Activator Class which is the key to late binding.
You are going to be using the Assembly class to load the library during run time, getting the type declared in that library and instatntiating and running those types.
Good luck
PT Exorcist
Aug 2nd, 2002, 10:00 AM
hmmmmmm
PT Exorcist
Aug 2nd, 2002, 10:50 AM
isnt there any tuturial around who could explain this with some detail?
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.