how to adding function to an existing class?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jjk1407@gmail.com

    #1

    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!

  • sloan

    #2
    Re: how to adding function to an existing class?


    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






    <jjk1407@gmail. comwrote in message
    news:1179775704 .761892.26760@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!
    >

    Comment

    • Trevor Benedict R

      #3
      Re: how to adding function to an existing class?

      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



      <jjk1407@gmail. comwrote in message
      news:1179775704 .761892.26760@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!
      >

      Comment

      • Phill W.

        #4
        Re: how to adding function to an existing class?

        jjk1407@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.

        Comment

        Working...