Help with Inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D Miller

    Help with Inheritance

    This may be a basic question, but it sure has me stumpted..


    I have two classes, Class1 and Class2. Class 2 inherits class one. Each
    class has some varibles that need to be reset from time to time, so I have
    created a method call "Clear" that does that. So my question is when using
    "Clear" in an instance of class two, the clear method in Class one does not
    get called, is there some way of excucting both "Clear" Methods in a single
    call... See the code below for what I mean...

    There must be a simple way of doing this, and I suspect I'm going to feel
    pretty foolish when someone points it out, but it sure has me stumped at the
    moment...

    Thank you,
    David


    Public Class1
    dim mQty as integer
    dim mPrice as double


    Public Sub Clear
    mPrice = 0
    mQty =0
    end sub

    Public Property Price as Double
    Get
    return mPrice
    end get
    Set(ByVal Value as Double)
    mPrice = Value
    end set
    end property

    Public Property Qty as Integer
    Get
    return mQty
    end get
    Set(ByVal Value as Integer)
    mQty = Value
    end set
    end property
    end class

    Public Class2
    inherits Class1
    dim mInvoice as integer


    Public Shadows Sub Clear
    ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING THIS
    METHOD RUN THE CLEAR METHOD OF CLASS1?
    mInvoice = 0
    end sub


    Public Property Invoice as Integer
    Get
    return mInvoice
    end get
    Set(ByVal Value as Integer)
    mInvoice = Value
    end set
    end property
    end class

    i


  • Lloyd Sheen

    #2
    Re: Help with Inheritance

    If I understand you have the two classes both with Clear methods. If you
    call the Class2.Clear simply (depending on the language used) add a call to
    the Clear in the parent class.

    For VB.NET the syntax is MyBase.Clear()
    For C# it is base.Clear();

    Lloyd Sheen

    "D Miller" <demiller2002@y ahoo.com> wrote in message
    news:QLUdc.4444 $A_4.974@newsre ad1.news.pas.ea rthlink.net...[color=blue]
    > This may be a basic question, but it sure has me stumpted..
    >
    >
    > I have two classes, Class1 and Class2. Class 2 inherits class one.[/color]
    Each[color=blue]
    > class has some varibles that need to be reset from time to time, so I have
    > created a method call "Clear" that does that. So my question is when[/color]
    using[color=blue]
    > "Clear" in an instance of class two, the clear method in Class one does[/color]
    not[color=blue]
    > get called, is there some way of excucting both "Clear" Methods in a[/color]
    single[color=blue]
    > call... See the code below for what I mean...
    >
    > There must be a simple way of doing this, and I suspect I'm going to feel
    > pretty foolish when someone points it out, but it sure has me stumped at[/color]
    the[color=blue]
    > moment...
    >
    > Thank you,
    > David
    >
    >
    > Public Class1
    > dim mQty as integer
    > dim mPrice as double
    >
    >
    > Public Sub Clear
    > mPrice = 0
    > mQty =0
    > end sub
    >
    > Public Property Price as Double
    > Get
    > return mPrice
    > end get
    > Set(ByVal Value as Double)
    > mPrice = Value
    > end set
    > end property
    >
    > Public Property Qty as Integer
    > Get
    > return mQty
    > end get
    > Set(ByVal Value as Integer)
    > mQty = Value
    > end set
    > end property
    > end class
    >
    > Public Class2
    > inherits Class1
    > dim mInvoice as integer
    >
    >
    > Public Shadows Sub Clear
    > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING[/color]
    THIS[color=blue]
    > METHOD RUN THE CLEAR METHOD OF CLASS1?
    > mInvoice = 0
    > end sub
    >
    >
    > Public Property Invoice as Integer
    > Get
    > return mInvoice
    > end get
    > Set(ByVal Value as Integer)
    > mInvoice = Value
    > end set
    > end property
    > end class
    >
    > i
    >
    >[/color]


    Comment

    • Lloyd Sheen

      #3
      Re: Help with Inheritance

      If I understand you have the two classes both with Clear methods. If you
      call the Class2.Clear simply (depending on the language used) add a call to
      the Clear in the parent class.

      For VB.NET the syntax is MyBase.Clear()
      For C# it is base.Clear();

      Lloyd Sheen

      "D Miller" <demiller2002@y ahoo.com> wrote in message
      news:QLUdc.4444 $A_4.974@newsre ad1.news.pas.ea rthlink.net...[color=blue]
      > This may be a basic question, but it sure has me stumpted..
      >
      >
      > I have two classes, Class1 and Class2. Class 2 inherits class one.[/color]
      Each[color=blue]
      > class has some varibles that need to be reset from time to time, so I have
      > created a method call "Clear" that does that. So my question is when[/color]
      using[color=blue]
      > "Clear" in an instance of class two, the clear method in Class one does[/color]
      not[color=blue]
      > get called, is there some way of excucting both "Clear" Methods in a[/color]
      single[color=blue]
      > call... See the code below for what I mean...
      >
      > There must be a simple way of doing this, and I suspect I'm going to feel
      > pretty foolish when someone points it out, but it sure has me stumped at[/color]
      the[color=blue]
      > moment...
      >
      > Thank you,
      > David
      >
      >
      > Public Class1
      > dim mQty as integer
      > dim mPrice as double
      >
      >
      > Public Sub Clear
      > mPrice = 0
      > mQty =0
      > end sub
      >
      > Public Property Price as Double
      > Get
      > return mPrice
      > end get
      > Set(ByVal Value as Double)
      > mPrice = Value
      > end set
      > end property
      >
      > Public Property Qty as Integer
      > Get
      > return mQty
      > end get
      > Set(ByVal Value as Integer)
      > mQty = Value
      > end set
      > end property
      > end class
      >
      > Public Class2
      > inherits Class1
      > dim mInvoice as integer
      >
      >
      > Public Shadows Sub Clear
      > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING[/color]
      THIS[color=blue]
      > METHOD RUN THE CLEAR METHOD OF CLASS1?
      > mInvoice = 0
      > end sub
      >
      >
      > Public Property Invoice as Integer
      > Get
      > return mInvoice
      > end get
      > Set(ByVal Value as Integer)
      > mInvoice = Value
      > end set
      > end property
      > end class
      >
      > i
      >
      >[/color]


      Comment

      • D Miller

        #4
        Re: Help with Inheritance

        What about calling it from the "child class"?
        Thanks.


        "Lloyd Sheen" <sqlguyremoveal lofthis@tostops pamhotmail.com> wrote in message
        news:rUUdc.551$ 0Qw.146@news04. bloor.is.net.ca ble.rogers.com. ..[color=blue]
        > If I understand you have the two classes both with Clear methods. If you
        > call the Class2.Clear simply (depending on the language used) add a call[/color]
        to[color=blue]
        > the Clear in the parent class.
        >
        > For VB.NET the syntax is MyBase.Clear()
        > For C# it is base.Clear();
        >
        > Lloyd Sheen
        >
        > "D Miller" <demiller2002@y ahoo.com> wrote in message
        > news:QLUdc.4444 $A_4.974@newsre ad1.news.pas.ea rthlink.net...[color=green]
        > > This may be a basic question, but it sure has me stumpted..
        > >
        > >
        > > I have two classes, Class1 and Class2. Class 2 inherits class one.[/color]
        > Each[color=green]
        > > class has some varibles that need to be reset from time to time, so I[/color][/color]
        have[color=blue][color=green]
        > > created a method call "Clear" that does that. So my question is when[/color]
        > using[color=green]
        > > "Clear" in an instance of class two, the clear method in Class one does[/color]
        > not[color=green]
        > > get called, is there some way of excucting both "Clear" Methods in a[/color]
        > single[color=green]
        > > call... See the code below for what I mean...
        > >
        > > There must be a simple way of doing this, and I suspect I'm going to[/color][/color]
        feel[color=blue][color=green]
        > > pretty foolish when someone points it out, but it sure has me stumped at[/color]
        > the[color=green]
        > > moment...
        > >
        > > Thank you,
        > > David
        > >
        > >
        > > Public Class1
        > > dim mQty as integer
        > > dim mPrice as double
        > >
        > >
        > > Public Sub Clear
        > > mPrice = 0
        > > mQty =0
        > > end sub
        > >
        > > Public Property Price as Double
        > > Get
        > > return mPrice
        > > end get
        > > Set(ByVal Value as Double)
        > > mPrice = Value
        > > end set
        > > end property
        > >
        > > Public Property Qty as Integer
        > > Get
        > > return mQty
        > > end get
        > > Set(ByVal Value as Integer)
        > > mQty = Value
        > > end set
        > > end property
        > > end class
        > >
        > > Public Class2
        > > inherits Class1
        > > dim mInvoice as integer
        > >
        > >
        > > Public Shadows Sub Clear
        > > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING[/color]
        > THIS[color=green]
        > > METHOD RUN THE CLEAR METHOD OF CLASS1?
        > > mInvoice = 0
        > > end sub
        > >
        > >
        > > Public Property Invoice as Integer
        > > Get
        > > return mInvoice
        > > end get
        > > Set(ByVal Value as Integer)
        > > mInvoice = Value
        > > end set
        > > end property
        > > end class
        > >
        > > i
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • D Miller

          #5
          Re: Help with Inheritance

          What about calling it from the "child class"?
          Thanks.


          "Lloyd Sheen" <sqlguyremoveal lofthis@tostops pamhotmail.com> wrote in message
          news:rUUdc.551$ 0Qw.146@news04. bloor.is.net.ca ble.rogers.com. ..[color=blue]
          > If I understand you have the two classes both with Clear methods. If you
          > call the Class2.Clear simply (depending on the language used) add a call[/color]
          to[color=blue]
          > the Clear in the parent class.
          >
          > For VB.NET the syntax is MyBase.Clear()
          > For C# it is base.Clear();
          >
          > Lloyd Sheen
          >
          > "D Miller" <demiller2002@y ahoo.com> wrote in message
          > news:QLUdc.4444 $A_4.974@newsre ad1.news.pas.ea rthlink.net...[color=green]
          > > This may be a basic question, but it sure has me stumpted..
          > >
          > >
          > > I have two classes, Class1 and Class2. Class 2 inherits class one.[/color]
          > Each[color=green]
          > > class has some varibles that need to be reset from time to time, so I[/color][/color]
          have[color=blue][color=green]
          > > created a method call "Clear" that does that. So my question is when[/color]
          > using[color=green]
          > > "Clear" in an instance of class two, the clear method in Class one does[/color]
          > not[color=green]
          > > get called, is there some way of excucting both "Clear" Methods in a[/color]
          > single[color=green]
          > > call... See the code below for what I mean...
          > >
          > > There must be a simple way of doing this, and I suspect I'm going to[/color][/color]
          feel[color=blue][color=green]
          > > pretty foolish when someone points it out, but it sure has me stumped at[/color]
          > the[color=green]
          > > moment...
          > >
          > > Thank you,
          > > David
          > >
          > >
          > > Public Class1
          > > dim mQty as integer
          > > dim mPrice as double
          > >
          > >
          > > Public Sub Clear
          > > mPrice = 0
          > > mQty =0
          > > end sub
          > >
          > > Public Property Price as Double
          > > Get
          > > return mPrice
          > > end get
          > > Set(ByVal Value as Double)
          > > mPrice = Value
          > > end set
          > > end property
          > >
          > > Public Property Qty as Integer
          > > Get
          > > return mQty
          > > end get
          > > Set(ByVal Value as Integer)
          > > mQty = Value
          > > end set
          > > end property
          > > end class
          > >
          > > Public Class2
          > > inherits Class1
          > > dim mInvoice as integer
          > >
          > >
          > > Public Shadows Sub Clear
          > > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING[/color]
          > THIS[color=green]
          > > METHOD RUN THE CLEAR METHOD OF CLASS1?
          > > mInvoice = 0
          > > end sub
          > >
          > >
          > > Public Property Invoice as Integer
          > > Get
          > > return mInvoice
          > > end get
          > > Set(ByVal Value as Integer)
          > > mInvoice = Value
          > > end set
          > > end property
          > > end class
          > >
          > > i
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • EricJ

            #6
            Re: Help with Inheritance

            I think thats w Lloyd Sheen meanth

            cl1
            public sub clear()
            'code
            end sub

            cl2 : cl1
            public sub clear()
            MyBase.Clear()
            'code
            end sub

            hope it helps

            eric

            "D Miller" <demiller2002@y ahoo.com> wrote in message
            news:MDVdc.4530 $A_4.4426@newsr ead1.news.pas.e arthlink.net...[color=blue]
            > What about calling it from the "child class"?
            > Thanks.
            >
            >
            > "Lloyd Sheen" <sqlguyremoveal lofthis@tostops pamhotmail.com> wrote in[/color]
            message[color=blue]
            > news:rUUdc.551$ 0Qw.146@news04. bloor.is.net.ca ble.rogers.com. ..[color=green]
            > > If I understand you have the two classes both with Clear methods. If[/color][/color]
            you[color=blue][color=green]
            > > call the Class2.Clear simply (depending on the language used) add a call[/color]
            > to[color=green]
            > > the Clear in the parent class.
            > >
            > > For VB.NET the syntax is MyBase.Clear()
            > > For C# it is base.Clear();
            > >
            > > Lloyd Sheen
            > >
            > > "D Miller" <demiller2002@y ahoo.com> wrote in message
            > > news:QLUdc.4444 $A_4.974@newsre ad1.news.pas.ea rthlink.net...[color=darkred]
            > > > This may be a basic question, but it sure has me stumpted..
            > > >
            > > >
            > > > I have two classes, Class1 and Class2. Class 2 inherits class one.[/color]
            > > Each[color=darkred]
            > > > class has some varibles that need to be reset from time to time, so I[/color][/color]
            > have[color=green][color=darkred]
            > > > created a method call "Clear" that does that. So my question is when[/color]
            > > using[color=darkred]
            > > > "Clear" in an instance of class two, the clear method in Class one[/color][/color][/color]
            does[color=blue][color=green]
            > > not[color=darkred]
            > > > get called, is there some way of excucting both "Clear" Methods in a[/color]
            > > single[color=darkred]
            > > > call... See the code below for what I mean...
            > > >
            > > > There must be a simple way of doing this, and I suspect I'm going to[/color][/color]
            > feel[color=green][color=darkred]
            > > > pretty foolish when someone points it out, but it sure has me stumped[/color][/color][/color]
            at[color=blue][color=green]
            > > the[color=darkred]
            > > > moment...
            > > >
            > > > Thank you,
            > > > David
            > > >
            > > >
            > > > Public Class1
            > > > dim mQty as integer
            > > > dim mPrice as double
            > > >
            > > >
            > > > Public Sub Clear
            > > > mPrice = 0
            > > > mQty =0
            > > > end sub
            > > >
            > > > Public Property Price as Double
            > > > Get
            > > > return mPrice
            > > > end get
            > > > Set(ByVal Value as Double)
            > > > mPrice = Value
            > > > end set
            > > > end property
            > > >
            > > > Public Property Qty as Integer
            > > > Get
            > > > return mQty
            > > > end get
            > > > Set(ByVal Value as Integer)
            > > > mQty = Value
            > > > end set
            > > > end property
            > > > end class
            > > >
            > > > Public Class2
            > > > inherits Class1
            > > > dim mInvoice as integer
            > > >
            > > >
            > > > Public Shadows Sub Clear
            > > > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING[/color]
            > > THIS[color=darkred]
            > > > METHOD RUN THE CLEAR METHOD OF CLASS1?
            > > > mInvoice = 0
            > > > end sub
            > > >
            > > >
            > > > Public Property Invoice as Integer
            > > > Get
            > > > return mInvoice
            > > > end get
            > > > Set(ByVal Value as Integer)
            > > > mInvoice = Value
            > > > end set
            > > > end property
            > > > end class
            > > >
            > > > i
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • EricJ

              #7
              Re: Help with Inheritance

              I think thats w Lloyd Sheen meanth

              cl1
              public sub clear()
              'code
              end sub

              cl2 : cl1
              public sub clear()
              MyBase.Clear()
              'code
              end sub

              hope it helps

              eric

              "D Miller" <demiller2002@y ahoo.com> wrote in message
              news:MDVdc.4530 $A_4.4426@newsr ead1.news.pas.e arthlink.net...[color=blue]
              > What about calling it from the "child class"?
              > Thanks.
              >
              >
              > "Lloyd Sheen" <sqlguyremoveal lofthis@tostops pamhotmail.com> wrote in[/color]
              message[color=blue]
              > news:rUUdc.551$ 0Qw.146@news04. bloor.is.net.ca ble.rogers.com. ..[color=green]
              > > If I understand you have the two classes both with Clear methods. If[/color][/color]
              you[color=blue][color=green]
              > > call the Class2.Clear simply (depending on the language used) add a call[/color]
              > to[color=green]
              > > the Clear in the parent class.
              > >
              > > For VB.NET the syntax is MyBase.Clear()
              > > For C# it is base.Clear();
              > >
              > > Lloyd Sheen
              > >
              > > "D Miller" <demiller2002@y ahoo.com> wrote in message
              > > news:QLUdc.4444 $A_4.974@newsre ad1.news.pas.ea rthlink.net...[color=darkred]
              > > > This may be a basic question, but it sure has me stumpted..
              > > >
              > > >
              > > > I have two classes, Class1 and Class2. Class 2 inherits class one.[/color]
              > > Each[color=darkred]
              > > > class has some varibles that need to be reset from time to time, so I[/color][/color]
              > have[color=green][color=darkred]
              > > > created a method call "Clear" that does that. So my question is when[/color]
              > > using[color=darkred]
              > > > "Clear" in an instance of class two, the clear method in Class one[/color][/color][/color]
              does[color=blue][color=green]
              > > not[color=darkred]
              > > > get called, is there some way of excucting both "Clear" Methods in a[/color]
              > > single[color=darkred]
              > > > call... See the code below for what I mean...
              > > >
              > > > There must be a simple way of doing this, and I suspect I'm going to[/color][/color]
              > feel[color=green][color=darkred]
              > > > pretty foolish when someone points it out, but it sure has me stumped[/color][/color][/color]
              at[color=blue][color=green]
              > > the[color=darkred]
              > > > moment...
              > > >
              > > > Thank you,
              > > > David
              > > >
              > > >
              > > > Public Class1
              > > > dim mQty as integer
              > > > dim mPrice as double
              > > >
              > > >
              > > > Public Sub Clear
              > > > mPrice = 0
              > > > mQty =0
              > > > end sub
              > > >
              > > > Public Property Price as Double
              > > > Get
              > > > return mPrice
              > > > end get
              > > > Set(ByVal Value as Double)
              > > > mPrice = Value
              > > > end set
              > > > end property
              > > >
              > > > Public Property Qty as Integer
              > > > Get
              > > > return mQty
              > > > end get
              > > > Set(ByVal Value as Integer)
              > > > mQty = Value
              > > > end set
              > > > end property
              > > > end class
              > > >
              > > > Public Class2
              > > > inherits Class1
              > > > dim mInvoice as integer
              > > >
              > > >
              > > > Public Shadows Sub Clear
              > > > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING[/color]
              > > THIS[color=darkred]
              > > > METHOD RUN THE CLEAR METHOD OF CLASS1?
              > > > mInvoice = 0
              > > > end sub
              > > >
              > > >
              > > > Public Property Invoice as Integer
              > > > Get
              > > > return mInvoice
              > > > end get
              > > > Set(ByVal Value as Integer)
              > > > mInvoice = Value
              > > > end set
              > > > end property
              > > > end class
              > > >
              > > > i
              > > >
              > > >[/color]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Armin Zingler

                #8
                Re: Help with Inheritance

                "D Miller" <demiller2002@y ahoo.com> schrieb[color=blue]
                > Public Shadows Sub Clear
                > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF
                > HAVING THIS
                > METHOD RUN THE CLEAR METHOD OF CLASS1?
                > mInvoice = 0[/color]

                mybase.Clear
                [color=blue]
                > end sub[/color]



                --
                Armin

                How to quote and why:



                Comment

                • Armin Zingler

                  #9
                  Re: Help with Inheritance

                  "D Miller" <demiller2002@y ahoo.com> schrieb[color=blue]
                  > Public Shadows Sub Clear
                  > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF
                  > HAVING THIS
                  > METHOD RUN THE CLEAR METHOD OF CLASS1?
                  > mInvoice = 0[/color]

                  mybase.Clear
                  [color=blue]
                  > end sub[/color]



                  --
                  Armin

                  How to quote and why:



                  Comment

                  • Jay B. Harlow [MVP - Outlook]

                    #10
                    Re: Help with Inheritance

                    D Miller,
                    In addition to the other's comments I would recommend NOT using Shadows
                    here, I would recommend making Clear Overridable.

                    Making Clear Overridable will allow Class2.Clear to execute if you put a
                    Class2 object in a Class1 variable. If you left Class2.Clear Shadows, only
                    Class1.Clear would be called...
                    [color=blue]
                    > Public Class Class1[/color]
                    [color=blue]
                    > Public Overridable Sub Clear
                    > mPrice = 0
                    > mQty =0
                    > end sub[/color]
                    [color=blue]
                    > end class[/color]
                    [color=blue]
                    > Public Class Class2
                    > inherits Class1[/color]
                    [color=blue]
                    > Public Overrides Sub Clear[/color]
                    MyBase.Clear()[color=blue]
                    > mInvoice = 0
                    > end sub[/color]
                    [color=blue]
                    > end class[/color]

                    Then you will be able to do:

                    Dim c As Class1() = New Class2()
                    c.Clear()

                    And Class2.Clear will be called, which will call Class1.Clear.

                    I tend to reserve Shadows for upgrade situations where the base method is
                    introduced that is not compatible with a derived method & a couple of other
                    specialized cases...

                    Hope this helps
                    Jay


                    "D Miller" <demiller2002@y ahoo.com> wrote in message
                    news:QLUdc.4444 $A_4.974@newsre ad1.news.pas.ea rthlink.net...[color=blue]
                    > This may be a basic question, but it sure has me stumpted..
                    >
                    >
                    > I have two classes, Class1 and Class2. Class 2 inherits class one.[/color]
                    Each[color=blue]
                    > class has some varibles that need to be reset from time to time, so I have
                    > created a method call "Clear" that does that. So my question is when[/color]
                    using[color=blue]
                    > "Clear" in an instance of class two, the clear method in Class one does[/color]
                    not[color=blue]
                    > get called, is there some way of excucting both "Clear" Methods in a[/color]
                    single[color=blue]
                    > call... See the code below for what I mean...
                    >
                    > There must be a simple way of doing this, and I suspect I'm going to feel
                    > pretty foolish when someone points it out, but it sure has me stumped at[/color]
                    the[color=blue]
                    > moment...
                    >
                    > Thank you,
                    > David
                    >
                    >
                    > Public Class1
                    > dim mQty as integer
                    > dim mPrice as double
                    >
                    >
                    > Public Sub Clear
                    > mPrice = 0
                    > mQty =0
                    > end sub
                    >
                    > Public Property Price as Double
                    > Get
                    > return mPrice
                    > end get
                    > Set(ByVal Value as Double)
                    > mPrice = Value
                    > end set
                    > end property
                    >
                    > Public Property Qty as Integer
                    > Get
                    > return mQty
                    > end get
                    > Set(ByVal Value as Integer)
                    > mQty = Value
                    > end set
                    > end property
                    > end class
                    >
                    > Public Class2
                    > inherits Class1
                    > dim mInvoice as integer
                    >
                    >
                    > Public Shadows Sub Clear
                    > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING[/color]
                    THIS[color=blue]
                    > METHOD RUN THE CLEAR METHOD OF CLASS1?
                    > mInvoice = 0
                    > end sub
                    >
                    >
                    > Public Property Invoice as Integer
                    > Get
                    > return mInvoice
                    > end get
                    > Set(ByVal Value as Integer)
                    > mInvoice = Value
                    > end set
                    > end property
                    > end class
                    >
                    > i
                    >
                    >[/color]


                    Comment

                    • Jay B. Harlow [MVP - Outlook]

                      #11
                      Re: Help with Inheritance

                      D Miller,
                      In addition to the other's comments I would recommend NOT using Shadows
                      here, I would recommend making Clear Overridable.

                      Making Clear Overridable will allow Class2.Clear to execute if you put a
                      Class2 object in a Class1 variable. If you left Class2.Clear Shadows, only
                      Class1.Clear would be called...
                      [color=blue]
                      > Public Class Class1[/color]
                      [color=blue]
                      > Public Overridable Sub Clear
                      > mPrice = 0
                      > mQty =0
                      > end sub[/color]
                      [color=blue]
                      > end class[/color]
                      [color=blue]
                      > Public Class Class2
                      > inherits Class1[/color]
                      [color=blue]
                      > Public Overrides Sub Clear[/color]
                      MyBase.Clear()[color=blue]
                      > mInvoice = 0
                      > end sub[/color]
                      [color=blue]
                      > end class[/color]

                      Then you will be able to do:

                      Dim c As Class1() = New Class2()
                      c.Clear()

                      And Class2.Clear will be called, which will call Class1.Clear.

                      I tend to reserve Shadows for upgrade situations where the base method is
                      introduced that is not compatible with a derived method & a couple of other
                      specialized cases...

                      Hope this helps
                      Jay


                      "D Miller" <demiller2002@y ahoo.com> wrote in message
                      news:QLUdc.4444 $A_4.974@newsre ad1.news.pas.ea rthlink.net...[color=blue]
                      > This may be a basic question, but it sure has me stumpted..
                      >
                      >
                      > I have two classes, Class1 and Class2. Class 2 inherits class one.[/color]
                      Each[color=blue]
                      > class has some varibles that need to be reset from time to time, so I have
                      > created a method call "Clear" that does that. So my question is when[/color]
                      using[color=blue]
                      > "Clear" in an instance of class two, the clear method in Class one does[/color]
                      not[color=blue]
                      > get called, is there some way of excucting both "Clear" Methods in a[/color]
                      single[color=blue]
                      > call... See the code below for what I mean...
                      >
                      > There must be a simple way of doing this, and I suspect I'm going to feel
                      > pretty foolish when someone points it out, but it sure has me stumped at[/color]
                      the[color=blue]
                      > moment...
                      >
                      > Thank you,
                      > David
                      >
                      >
                      > Public Class1
                      > dim mQty as integer
                      > dim mPrice as double
                      >
                      >
                      > Public Sub Clear
                      > mPrice = 0
                      > mQty =0
                      > end sub
                      >
                      > Public Property Price as Double
                      > Get
                      > return mPrice
                      > end get
                      > Set(ByVal Value as Double)
                      > mPrice = Value
                      > end set
                      > end property
                      >
                      > Public Property Qty as Integer
                      > Get
                      > return mQty
                      > end get
                      > Set(ByVal Value as Integer)
                      > mQty = Value
                      > end set
                      > end property
                      > end class
                      >
                      > Public Class2
                      > inherits Class1
                      > dim mInvoice as integer
                      >
                      >
                      > Public Shadows Sub Clear
                      > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF HAVING[/color]
                      THIS[color=blue]
                      > METHOD RUN THE CLEAR METHOD OF CLASS1?
                      > mInvoice = 0
                      > end sub
                      >
                      >
                      > Public Property Invoice as Integer
                      > Get
                      > return mInvoice
                      > end get
                      > Set(ByVal Value as Integer)
                      > mInvoice = Value
                      > end set
                      > end property
                      > end class
                      >
                      > i
                      >
                      >[/color]


                      Comment

                      • D Miller

                        #12
                        Re: Help with Inheritance

                        I figured it would be something simple, thanks!

                        "Armin Zingler" <az.nospam@free net.de> wrote in message
                        news:407854e6$1 $141$9b622d9e@n ews.freenet.de. ..[color=blue]
                        > "D Miller" <demiller2002@y ahoo.com> schrieb[color=green]
                        > > Public Shadows Sub Clear
                        > > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF
                        > > HAVING THIS
                        > > METHOD RUN THE CLEAR METHOD OF CLASS1?
                        > > mInvoice = 0[/color]
                        >
                        > mybase.Clear
                        >[color=green]
                        > > end sub[/color]
                        >
                        >
                        >
                        > --
                        > Armin
                        >
                        > How to quote and why:
                        > http://www.plig.net/nnq/nquote.html
                        > http://www.netmeister.org/news/learn2quote.html
                        >[/color]


                        Comment

                        • D Miller

                          #13
                          Re: Help with Inheritance

                          I figured it would be something simple, thanks!

                          "Armin Zingler" <az.nospam@free net.de> wrote in message
                          news:407854e6$1 $141$9b622d9e@n ews.freenet.de. ..[color=blue]
                          > "D Miller" <demiller2002@y ahoo.com> schrieb[color=green]
                          > > Public Shadows Sub Clear
                          > > ' HERE IS WHERE THE QUESTION IS. IS THERE SOME WAY OF
                          > > HAVING THIS
                          > > METHOD RUN THE CLEAR METHOD OF CLASS1?
                          > > mInvoice = 0[/color]
                          >
                          > mybase.Clear
                          >[color=green]
                          > > end sub[/color]
                          >
                          >
                          >
                          > --
                          > Armin
                          >
                          > How to quote and why:
                          > http://www.plig.net/nnq/nquote.html
                          > http://www.netmeister.org/news/learn2quote.html
                          >[/color]


                          Comment

                          Working...