473,403 Members | 2,071 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,403 software developers and data experts.

how to adding function to an existing class?

hello,

i am a newbie to vb.net. i met a problem with vb on adding function to
an existing class.

when i was trying to add a function, say myfunc, to a class, myclass,
using "public shared function myfunc", and called myfunc in somewhere
else. theres always a complier error said "myfunc is not a member of
myclass". and in object browser, ive found that there are two classes,
myclass and myclass [1.0.0.0]. in the content of myclass, there lies
myfunc, but in myclass [1.0.0.0], there has every old functions except
myfunc.

i totally have no clue on why it happened. does anyone can help?

thanks a lot!

May 21 '07 #1
3 2249

public shared function myfunc1

OR
public function myfunc2
the first one, is a static(or shared in vb.net) function.
you call it by

myclass.myfunc1

the second function (because its not static/shared), you have to create a
myclass

dim mc as myclass = new myclass
mc.myfunc2


<jj*****@gmail.comwrote in message
news:11*********************@b40g2000prd.googlegro ups.com...
hello,

i am a newbie to vb.net. i met a problem with vb on adding function to
an existing class.

when i was trying to add a function, say myfunc, to a class, myclass,
using "public shared function myfunc", and called myfunc in somewhere
else. theres always a complier error said "myfunc is not a member of
myclass". and in object browser, ive found that there are two classes,
myclass and myclass [1.0.0.0]. in the content of myclass, there lies
myfunc, but in myclass [1.0.0.0], there has every old functions except
myfunc.

i totally have no clue on why it happened. does anyone can help?

thanks a lot!

May 21 '07 #2
I assume you are have a calls called myClass and you want to add a function
to this class called myFunction. If this is what you want then this is what
you need to do.

1) declare myNewClass and inherit it from myClass (this is the one that you
already have)
2) add your function to myNewClass
3) Create and start using instances of myNewClass or if it is shared
function then it does not make any difference. You may call it without
creating an instance of the class.
Refer to http://www.samspublishing.com/articl...p?p=23262&rl=1 for
an example

You can gooogle and read more about Inheritance.

Regards,

Trevor Benedict
MCSD

<jj*****@gmail.comwrote in message
news:11*********************@b40g2000prd.googlegro ups.com...
hello,

i am a newbie to vb.net. i met a problem with vb on adding function to
an existing class.

when i was trying to add a function, say myfunc, to a class, myclass,
using "public shared function myfunc", and called myfunc in somewhere
else. theres always a complier error said "myfunc is not a member of
myclass". and in object browser, ive found that there are two classes,
myclass and myclass [1.0.0.0]. in the content of myclass, there lies
myfunc, but in myclass [1.0.0.0], there has every old functions except
myfunc.

i totally have no clue on why it happened. does anyone can help?

thanks a lot!

May 21 '07 #3
jj*****@gmail.com wrote:
when i was trying to add a function, say myfunc, to a class, myclass,
using "public shared function myfunc", and called myfunc in somewhere
else. theres always a complier error said "myfunc is not a member of
myclass". and in object browser, ive found that there are two classes,
myclass and myclass [1.0.0.0]. in the content of myclass, there lies
myfunc, but in myclass [1.0.0.0], there has every old functions except
myfunc.
Sounds like you have a Reference to an external assembly MyClass.
Despite having the same name, they are seen as completely different
Types by the Framework.

Presumably, the code attempting (and failing) to call your new method is
using the /other/ Reference and, therefore, picking up the "old" version
that doesn't contain your new method.

HTH,
Phill W.

May 22 '07 #4

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

Similar topics

8
by: Kevin Little | last post by:
#!/usr/bin/env python ''' I want to dynamically add or replace bound methods in a class. I want the modifications to be immediately effective across all instances, whether created before or...
1
by: The Eclectic Electric | last post by:
I'd be very grateful if anyone could help me with this. From my limited knowledge of Javascript I don't think it is possible, but I'll punt anyway. I downloaded and very slightly adapted this...
1
by: Allen | last post by:
I need a way to add a method to an existing instance, but be as close as possible to normal instance methods. Using 'new' module or such code as 'def addfunc(...): def helper(...) .. setattr(...)'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.