473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

generic function in a class to be used by reference only

From asp.net (vb) or another winforms vb.net application I would like to us
generic functions compiled in .dl
Of course a reference is made to the .dl

All the examples show a component to be compiled as a creatable objec
I would like to use the functions more like a librar

for instanc

public Class MyComponen
public function GetText() as strin
return "This is text
end functio
end clas

New project will use it like

dim mycomp as mycomponen
dim s as strin

s = mycomp.GetTex

In vb6 I could compile a .dll to use the function global multiuse withou
the need to instantiate an object firs
like thi

- make a reference to mycomponent.dl

dim s=GetText (directly without an object

This must be possible in .net because all the FrameWor
components work like tha
just import system.data.sqlclient and I can use all the functions from sqlclien

Can anyone give a hint because all solutions upto now do it by instantiating a

thank you elka
Nov 20 '05 #1
4 1287
* "=?Utf-8?B?ZWxrYQ==?=" <an*******@discussions.microsoft.com> scripsit:
From asp.net (vb) or another winforms vb.net application I would like to use
generic functions compiled in .dll
Of course a reference is made to the .dll

All the examples show a component to be compiled as a creatable object
I would like to use the functions more like a library

for instance

public Class MyComponent
public function GetText() as string
return "This is text"
end function
end class

New project will use it like :

dim mycomp as mycomponent
dim s as string

s = mycomp.GetText
In vb6 I could compile a .dll to use the function global multiuse without
the need to instantiate an object first
like this

- make a reference to mycomponent.dll

dim s=GetText (directly without an object)

This must be possible in .net because all the FrameWork
components work like that
just import system.data.sqlclient and I can use all the functions from sqlclient

Can anyone give a hint because all solutions upto now do it by instantiating a


'Public Shared Function GetText(...) As String' will allow you to call
the function using 'MyComponent.GetText(...)' (without instantiating
it).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
Elka,
In addition to use Shared within a class as Herfried showed. (which is what
I prefer as its better encapsulated).

You can define GetText within a public module:
public Class MyComponent
public Shared function GetText() as string
return "This is text"
end function
end class public Module MyComponent
public function GetText() as string
return "This is text"
end function
end Module
The first requires you to use:

s = MyComponent.GetText()

While the second allows:

s = GetText()

I prefer the first as its obvious that the GetText function is coming from
the MyComponent type.

Hope this helps
Jay

"elka" <an*******@discussions.microsoft.com> wrote in message
news:E9**********************************@microsof t.com... From asp.net (vb) or another winforms vb.net application I would like to use generic functions compiled in .dll
Of course a reference is made to the .dll

All the examples show a component to be compiled as a creatable object
I would like to use the functions more like a library

for instance

public Class MyComponent
public function GetText() as string
return "This is text"
end function
end class

New project will use it like :

dim mycomp as mycomponent
dim s as string

s = mycomp.GetText
In vb6 I could compile a .dll to use the function global multiuse without
the need to instantiate an object first
like this

- make a reference to mycomponent.dll

dim s=GetText (directly without an object)

This must be possible in .net because all the FrameWork
components work like that
just import system.data.sqlclient and I can use all the functions from sqlclient
Can anyone give a hint because all solutions upto now do it by instantiating a
thank you elka

Nov 20 '05 #3
Jay,

* "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> scripsit:
public Class MyComponent
public Shared function GetText() as string
return "This is text"
end function
end class

public Module MyComponent
public function GetText() as string
return "This is text"
end function
end Module


The first requires you to use:

s = MyComponent.GetText()

While the second allows:

s = GetText()

I prefer the first as its obvious that the GetText function is coming from
the MyComponent type.


In addition to what you are saying:

You can import the class so you can use the shared method without
qualifying it. But I think that's not a good idea...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
Herfried,
D'oh!
You can import the class so you can use the shared method without
qualifying it. But I think that's not a good idea...
I meant to add the import the class to make it a module trick ;-)

I rarely use the import class trick, however it is handy for truly global
functions, such as System.Math

Jay

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2g************@uni-berlin.de... Jay,

* "Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> scripsit:
public Class MyComponent
public Shared function GetText() as string
return "This is text"
end function
end class

public Module MyComponent
public function GetText() as string
return "This is text"
end function
end Module


The first requires you to use:

s = MyComponent.GetText()

While the second allows:

s = GetText()

I prefer the first as its obvious that the GetText function is coming from the MyComponent type.


In addition to what you are saying:

You can import the class so you can use the shared method without
qualifying it. But I think that's not a good idea...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
by: Steven Bethard | last post by:
I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
2
by: Jon Davis | last post by:
The garbage handler in the .NET framework is handy. When objects fall out of scope, they are automatically destroyed, and the programmer doesn't have to worry about deallocating the memory space...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
22
by: Adam Clauss | last post by:
OK, I have class A defined as follows: class A { A(Queue<B> queue) { ... } } Now, I then have a subclass of both classes A and B. The subclass of A (SubA), more specifically is passed a...
1
by: interX | last post by:
Hi I'm new in VC++ and have a question to generics. I have a generic class, which contains an array of the generic type. This array I can pin and then I would like to get an unmanaged pointer to...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
7
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
26
by: raylopez99 | last post by:
Here is a good example that shows generic delegate types. Read this through and you'll have an excellent understanding of how to use these types. You might say that the combination of the generic...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.