473,806 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2265

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******** *************@b 40g2000prd.goog legroups.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******** *************@b 40g2000prd.goog legroups.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.c om 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
2946
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 after the class was modified. I need this to work for both old ('classic') and new style classes, at both 2.3 and 2.4. I of course want to avoid side effects, and to make the solution as light-weight as possible.
1
2468
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 guy's Javascript "combo box" - http://sandy.mcarthur.org/javascript/select/select.html. It allows my users (when I get some!) to select from a list of preexisting options and also to add a new one by clicking on "add new". Essentially it's a select...
1
1738
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(...)' causes a cyclic reference which requires using 'gc.collect' to release the object. Also 'new' is deprecated. I also made a helper that uses weakref, but the problem is when the object is gone, existing instance method object would not work: ...
0
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10624
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10111
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5684
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.