how to adding function to an existing class?

J

jjk1407

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!
 
S

sloan

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
 
T

Trevor Benedict R

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/articles/article.asp?p=23262&rl=1 for
an example

You can gooogle and read more about Inheritance.

Regards,

Trevor Benedict
MCSD
 
P

Phill W.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top