471,602 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,602 software developers and data experts.

My Class

When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be accessed
in the same fashion.. e.g.

myclass.myfunction("parameter")
Nov 21 '05 #1
23 1344
Take a look at the "static" and "shared" keywords. One of these two should
do this for you. What you're looking for is a non-instanced class
interface.

Mike Ober.

"patang" <pa****@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be accessed in the same fashion.. e.g.

myclass.myfunction("parameter")


Nov 21 '05 #2
Take a look at the "static" and "shared" keywords. One of these two should
do this for you. What you're looking for is a non-instanced class
interface.

Mike Ober.

"patang" <pa****@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be accessed in the same fashion.. e.g.

myclass.myfunction("parameter")


Nov 21 '05 #3
I think you are talking about SHARED members. Triy using the SHARED keyword
when declaring your member. You should be able to access that class member
without instantiating an actual object first.

Hope this helps :o)

"patang" wrote:
When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be accessed
in the same fashion.. e.g.

myclass.myfunction("parameter")

Nov 21 '05 #4
I think you are talking about SHARED members. Triy using the SHARED keyword
when declaring your member. You should be able to access that class member
without instantiating an actual object first.

Hope this helps :o)

"patang" wrote:
When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be accessed
in the same fashion.. e.g.

myclass.myfunction("parameter")

Nov 21 '05 #5
"patang" <pa****@discussions.microsoft.com> schrieb:
When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be
accessed
in the same fashion..


There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6
"patang" <pa****@discussions.microsoft.com> schrieb:
When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be
accessed
in the same fashion..


There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7
Does this mean that LEFT or RIGHT functions (methods) are declared as SHARED
in the STRINGS class ?

"Herfried K. Wagner [MVP]" wrote:
"patang" <pa****@discussions.microsoft.com> schrieb:
When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be
accessed
in the same fashion..


There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #8
Does this mean that LEFT or RIGHT functions (methods) are declared as SHARED
in the STRINGS class ?

"Herfried K. Wagner [MVP]" wrote:
"patang" <pa****@discussions.microsoft.com> schrieb:
When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be
accessed
in the same fashion..


There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #9
I have one public function in the class and many private functions. Public
functions uses those private functions. When I declare the public function as
"SHARED" then I can't access the private function from within public
functions, it says: " ....Cannot refer to an instance member of a class from
within a shared method or shared member initializer without an explicit
instance of the class....."

"Herfried K. Wagner [MVP]" wrote:
"patang" <pa****@discussions.microsoft.com> schrieb:
When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be
accessed
in the same fashion..


There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #10
I have one public function in the class and many private functions. Public
functions uses those private functions. When I declare the public function as
"SHARED" then I can't access the private function from within public
functions, it says: " ....Cannot refer to an instance member of a class from
within a shared method or shared member initializer without an explicit
instance of the class....."

"Herfried K. Wagner [MVP]" wrote:
"patang" <pa****@discussions.microsoft.com> schrieb:
When I create my own class, to use the functions of that class I have to
create an object of that class and then I can access the functions of that
class,

for example:

dim obj1 as myclass
obj1 = new myclass
obj1.myfunction("parameter")

However, when I use .net class e.g. strings I do not need to create a
object, I can directly use it?

e.g.

x = strings.left("abc",2)

What do I have to do, so that the functions of my class can also be
accessed
in the same fashion..


There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #11
"Public Shared Function Left(ByVal str As String, ByVal Length As Integer)
As String
Member of Microsoft.VisualBasic.Strings"
- Microsoft documentation.

But there more classes with a method called 'Left'. And they can all do
other things. Check out the specific class for more info.

Does this mean that LEFT or RIGHT functions (methods) are declared as
SHARED
in the STRINGS class ?

"Herfried K. Wagner [MVP]" wrote:
"patang" <pa****@discussions.microsoft.com> schrieb:
> When I create my own class, to use the functions of that class I have
> to
> create an object of that class and then I can access the functions of
> that
> class,
>
> for example:
>
> dim obj1 as myclass
> obj1 = new myclass
> obj1.myfunction("parameter")
>
> However, when I use .net class e.g. strings I do not need to create a
> object, I can directly use it?
>
> e.g.
>
> x = strings.left("abc",2)
>
> What do I have to do, so that the functions of my class can also be
> accessed
> in the same fashion..


There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #12
"Public Shared Function Left(ByVal str As String, ByVal Length As Integer)
As String
Member of Microsoft.VisualBasic.Strings"
- Microsoft documentation.

But there more classes with a method called 'Left'. And they can all do
other things. Check out the specific class for more info.

Does this mean that LEFT or RIGHT functions (methods) are declared as
SHARED
in the STRINGS class ?

"Herfried K. Wagner [MVP]" wrote:
"patang" <pa****@discussions.microsoft.com> schrieb:
> When I create my own class, to use the functions of that class I have
> to
> create an object of that class and then I can access the functions of
> that
> class,
>
> for example:
>
> dim obj1 as myclass
> obj1 = new myclass
> obj1.myfunction("parameter")
>
> However, when I use .net class e.g. strings I do not need to create a
> object, I can directly use it?
>
> e.g.
>
> x = strings.left("abc",2)
>
> What do I have to do, so that the functions of my class can also be
> accessed
> in the same fashion..


There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #13
You have to make the 'Private' methods also 'Shared' if you want to use them
inside a 'Public Shared' method, or create an instance of the class inside
the 'Public Shared' instance and use that instance to call the 'Private'
methods.
"patang" <pa****@discussions.microsoft.com> schreef in bericht
news:64**********************************@microsof t.com...
I have one public function in the class and many private functions. Public
functions uses those private functions. When I declare the public function
as
"SHARED" then I can't access the private function from within public
functions, it says: " ....Cannot refer to an instance member of a class
from
within a shared method or shared member initializer without an explicit
instance of the class....."


"Herfried K. Wagner [MVP]" wrote:
"patang" <pa****@discussions.microsoft.com> schrieb:
> When I create my own class, to use the functions of that class I have
> to
> create an object of that class and then I can access the functions of
> that
> class,
>
> for example:
>
> dim obj1 as myclass
> obj1 = new myclass
> obj1.myfunction("parameter")
>
> However, when I use .net class e.g. strings I do not need to create a
> object, I can directly use it?
>
> e.g.
>
> x = strings.left("abc",2)
>
> What do I have to do, so that the functions of my class can also be
> accessed
> in the same fashion..


There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #14
You have to make the 'Private' methods also 'Shared' if you want to use them
inside a 'Public Shared' method, or create an instance of the class inside
the 'Public Shared' instance and use that instance to call the 'Private'
methods.
"patang" <pa****@discussions.microsoft.com> schreef in bericht
news:64**********************************@microsof t.com...
I have one public function in the class and many private functions. Public
functions uses those private functions. When I declare the public function
as
"SHARED" then I can't access the private function from within public
functions, it says: " ....Cannot refer to an instance member of a class
from
within a shared method or shared member initializer without an explicit
instance of the class....."


"Herfried K. Wagner [MVP]" wrote:
"patang" <pa****@discussions.microsoft.com> schrieb:
> When I create my own class, to use the functions of that class I have
> to
> create an object of that class and then I can access the functions of
> that
> class,
>
> for example:
>
> dim obj1 as myclass
> obj1 = new myclass
> obj1.myfunction("parameter")
>
> However, when I use .net class e.g. strings I do not need to create a
> object, I can directly use it?
>
> e.g.
>
> x = strings.left("abc",2)
>
> What do I have to do, so that the functions of my class can also be
> accessed
> in the same fashion..


There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #15
one more question:

In my solution only following are imported:

System
System.Data
System.Drawings
System.Windows.Form
System.XML

System.Data.Oledb

How come the methods of Strings class are accessible even though it has not
been imported in my solution?

"Qwert" wrote:
You have to make the 'Private' methods also 'Shared' if you want to use them
inside a 'Public Shared' method, or create an instance of the class inside
the 'Public Shared' instance and use that instance to call the 'Private'
methods.
"patang" <pa****@discussions.microsoft.com> schreef in bericht
news:64**********************************@microsof t.com...
I have one public function in the class and many private functions. Public
functions uses those private functions. When I declare the public function
as
"SHARED" then I can't access the private function from within public
functions, it says: " ....Cannot refer to an instance member of a class
from
within a shared method or shared member initializer without an explicit
instance of the class....."


"Herfried K. Wagner [MVP]" wrote:
"patang" <pa****@discussions.microsoft.com> schrieb:
> When I create my own class, to use the functions of that class I have
> to
> create an object of that class and then I can access the functions of
> that
> class,
>
> for example:
>
> dim obj1 as myclass
> obj1 = new myclass
> obj1.myfunction("parameter")
>
> However, when I use .net class e.g. strings I do not need to create a
> object, I can directly use it?
>
> e.g.
>
> x = strings.left("abc",2)
>
> What do I have to do, so that the functions of my class can also be
> accessed
> in the same fashion..

There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Nov 21 '05 #16
I'm guessing because you have "Microsoft.VisualBasic" in your import
statements of your project.

Right click on your project's name in the solution explorer and click on
properties. Select Common Properties -> Imports. There is a list with
Project Imports.

"patang" <pa****@discussions.microsoft.com> schreef in bericht
news:9E**********************************@microsof t.com...
one more question:

In my solution only following are imported:

System
System.Data
System.Drawings
System.Windows.Form
System.XML

System.Data.Oledb

How come the methods of Strings class are accessible even though it has
not
been imported in my solution?

"Qwert" wrote:
You have to make the 'Private' methods also 'Shared' if you want to use
them
inside a 'Public Shared' method, or create an instance of the class
inside
the 'Public Shared' instance and use that instance to call the 'Private'
methods.
"patang" <pa****@discussions.microsoft.com> schreef in bericht
news:64**********************************@microsof t.com...
>I have one public function in the class and many private functions.
>Public
> functions uses those private functions. When I declare the public
> function
> as
> "SHARED" then I can't access the private function from within public
> functions, it says: " ....Cannot refer to an instance member of a class
> from
> within a shared method or shared member initializer without an explicit
> instance of the class....."

>
>
>
> "Herfried K. Wagner [MVP]" wrote:
>
>> "patang" <pa****@discussions.microsoft.com> schrieb:
>> > When I create my own class, to use the functions of that class I
>> > have
>> > to
>> > create an object of that class and then I can access the functions
>> > of
>> > that
>> > class,
>> >
>> > for example:
>> >
>> > dim obj1 as myclass
>> > obj1 = new myclass
>> > obj1.myfunction("parameter")
>> >
>> > However, when I use .net class e.g. strings I do not need to create
>> > a
>> > object, I can directly use it?
>> >
>> > e.g.
>> >
>> > x = strings.left("abc",2)
>> >
>> > What do I have to do, so that the functions of my class can also be
>> > accessed
>> > in the same fashion..
>>
>> There are two ways to archieve what you want to do:
>>
>> * You can add the 'Shared' modifier to your function when
>> it's part of a class ('Public Shared Function...').
>>
>> * Or you can add the function to a module. 'Shared' is not
>> required when doing this. Functions defined in modules
>> are imported automatically and thus can be accessed
>> with their unqualified name (for example, 'Left' instead of
>> 'Strings.Left').
>>
>> --
>> M S Herfried K. Wagner
>> M V P <URL:http://dotnet.mvps.org/>
>> V B <URL:http://classicvb.org/petition/>
>>
>>


Nov 21 '05 #17

Your are right. "Microsoft.VisualBasic" is included in the list of imports
in my project.
"Qwert" wrote:
I'm guessing because you have "Microsoft.VisualBasic" in your import
statements of your project.

Right click on your project's name in the solution explorer and click on
properties. Select Common Properties -> Imports. There is a list with
Project Imports.

"patang" <pa****@discussions.microsoft.com> schreef in bericht
news:9E**********************************@microsof t.com...
one more question:

In my solution only following are imported:

System
System.Data
System.Drawings
System.Windows.Form
System.XML

System.Data.Oledb

How come the methods of Strings class are accessible even though it has
not
been imported in my solution?


Nov 21 '05 #18
"patang" <pa****@discussions.microsoft.com> schrieb:
Does this mean that LEFT or RIGHT functions (methods) are declared as
SHARED
in the STRINGS class ?


These functions are declared in the 'Strings' /module/. Methods declared in
a module are implicitly shared.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #19
I'm not 100% clear about what you mean... I understand completely about
having a public shared function in a class (I use one in a singleton
pattern class to hold some global variables). However, when I access that
function I need to fully qualify it (ie: myClass.myfunction() ). On your
second point, I'm not quite sure what you mean by adding the function to a
module.

I have a custom control library which I've built into a DLL. It contains
various *.VB files and each VB file has 1 or more classes defined. These
classes have public subs which I can access with the fully qualified name
(myClass.mySub). I do an IMPORT of this library dll wherever I need it.

What I would like to do is create a sub in this library that I can reference
without having to fully qualify it. It doesn't particularly matter if this
sub is in a class or not, I'd just like to be able to say
"myFunction(...)" without qualification (assume the name is unique).

Is there a way to do this?

Thanks, John

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OV**************@TK2MSFTNGP09.phx.gbl...
There are two ways to archieve what you want to do:

* You can add the 'Shared' modifier to your function when
it's part of a class ('Public Shared Function...').

* Or you can add the function to a module. 'Shared' is not
required when doing this. Functions defined in modules
are imported automatically and thus can be accessed
with their unqualified name (for example, 'Left' instead of
'Strings.Left').

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #20
"JohnR" <Jo******@hotmail.com> schrieb:
I'm not 100% clear about what you mean... I understand completely about
having a public shared function in a class (I use one in a singleton
pattern class to hold some global variables). However, when I access that
function I need to fully qualify it (ie: myClass.myfunction() ). On your
second point, I'm not quite sure what you mean by adding the function to a
module.

I have a custom control library which I've built into a DLL. It contains
various *.VB files and each VB file has 1 or more classes defined. These
classes have public subs which I can access with the fully qualified name
(myClass.mySub). I do an IMPORT of this library dll wherever I need it.

What I would like to do is create a sub in this library that I can
reference without having to fully qualify it. It doesn't particularly
matter if this sub is in a class or not, I'd just like to be able to say
"myFunction(...)" without qualification (assume the name is unique).

Is there a way to do this?

Add an additional file to your class library:

\\\
Public Module CommonFunctions
Public Sub DoSomething()
...
End Sub
End Module
///

In the project that uses the DLL import the DLL's root namespace
('ClassLibrary1'). Then you will be able to call 'DoEvents' without
qualification. If you are using a class instead of the module

\\\
Public Class CommonFunctions
Public Shared Sub DoSomething()
...
End Sub
End Class
///

and import the class in the client project that uses the DLL ('Imports
ClassLibrary1.CommonFunctions') you will be able to call 'DoSomething'
without fully qualifying it too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #21
Herfried,

I was writing as well an answer on the question when I saw yours.

You can for sure interpret my message wrong, therefore this message.

My message about shared and non shared is *not* based on your message. I had
already written it before that I saw yours.

Cor
Nov 21 '05 #22
Herfried,

I readed this while busy for a sample about
"Set Controls dinamically? is this for experts?"

and thought that this was your answer on that, so forget it.

Sorry

Cor
Nov 21 '05 #23
Herfried,

Thank you so much for your response. It worked out very well. The
thing I was missing was not realizing that you could do a:

Imports ClassLibrary.CommonFunctions

I thought you could only import the ClassLibrary itself... You really
cleared it up for me...

Thanks again, John

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
"JohnR" <Jo******@hotmail.com> schrieb:
I'm not 100% clear about what you mean... I understand completely about
having a public shared function in a class (I use one in a singleton
pattern class to hold some global variables). However, when I access
that function I need to fully qualify it (ie: myClass.myfunction() ).
On your second point, I'm not quite sure what you mean by adding the
function to a module.

I have a custom control library which I've built into a DLL. It contains
various *.VB files and each VB file has 1 or more classes defined. These
classes have public subs which I can access with the fully qualified name
(myClass.mySub). I do an IMPORT of this library dll wherever I need it.

What I would like to do is create a sub in this library that I can
reference without having to fully qualify it. It doesn't particularly
matter if this sub is in a class or not, I'd just like to be able to say
"myFunction(...)" without qualification (assume the name is unique).

Is there a way to do this?

Add an additional file to your class library:

\\\
Public Module CommonFunctions
Public Sub DoSomething()
...
End Sub
End Module
///

In the project that uses the DLL import the DLL's root namespace
('ClassLibrary1'). Then you will be able to call 'DoEvents' without
qualification. If you are using a class instead of the module

\\\
Public Class CommonFunctions
Public Shared Sub DoSomething()
...
End Sub
End Class
///

and import the class in the client project that uses the DLL ('Imports
ClassLibrary1.CommonFunctions') you will be able to call 'DoSomething'
without fully qualifying it too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #24

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fernando Rodriguez | last post: by
18 posts views Thread by John M. Gabriele | last post: by
13 posts views Thread by Bryan Parkoff | last post: by
8 posts views Thread by Bryan Parkoff | last post: by
21 posts views Thread by Jon Slaughter | last post: by
5 posts views Thread by Andy | last post: by
3 posts views Thread by Hamilton Woods | last post: by
reply views Thread by emin.shopper | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.