469,913 Members | 1,947 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,913 developers. It's quick & easy.

difference between ME and MYCLASS

Hi. I have the following question:

Since the methods are virtual, the following code produces "Child other
stuff" - the call runs as if pasted in Child... it runs in Parent but in the
context of Child.
-------------------------------
Module Module1

Sub Main()
Dim obj As New Child()
obj.DoSomething()
End Sub

End Module
-------------------------------
Public Class Parent

Public Sub DoSomething()
OtherStuff()
End Sub

Public Overridable Sub OtherStuff()
MsgBox("Parent other stuff")
End Sub

End Class
-------------------------------
Public Class Child
Inherits Parent

Public Overrides Sub OtherStuff()
MsgBox("Child other stuff")
End Sub

End Class
----------------------------------

Therefore, to avoid this, we have to change parent using MYCLASS....

-------------------------------
Public Class Parent

Public Sub DoSomething()
MyClass.OtherStuff()
End Sub

Public Overridable Sub OtherStuff()
MsgBox("Parent other stuff")
End Sub

End Class
-------------------------------

I'm confused as to what exactly is the difference between ME and MYCLASS -
why doesn't ME work in this case ? ME should refer to the current object,
(Parent, in this case), correct ?

Thank you.
Alex.
Mar 10 '06 #1
4 1206
Radu,

An answer from a guy who seldom is beside it in this kind of questions.

http://groups.google.com/group/micro...7b6507718c418f

I hope this helps,

Cor
Mar 10 '06 #2

Radu wrote:
Hi. I have the following question:

Since the methods are virtual, the following code produces "Child other
stuff" - the call runs as if pasted in Child... it runs in Parent but in the
context of Child.
-------------------------------
Module Module1

Sub Main()
Dim obj As New Child()
obj.DoSomething()
End Sub

End Module
-------------------------------
Public Class Parent

Public Sub DoSomething()
OtherStuff()
End Sub

Public Overridable Sub OtherStuff()
MsgBox("Parent other stuff")
End Sub

End Class
-------------------------------
Public Class Child
Inherits Parent

Public Overrides Sub OtherStuff()
MsgBox("Child other stuff")
End Sub

End Class
----------------------------------

Therefore, to avoid this, we have to change parent using MYCLASS....

-------------------------------
Public Class Parent

Public Sub DoSomething()
MyClass.OtherStuff()
End Sub

Public Overridable Sub OtherStuff()
MsgBox("Parent other stuff")
End Sub

End Class
-------------------------------

I'm confused as to what exactly is the difference between ME and MYCLASS -
why doesn't ME work in this case ? ME should refer to the current object,
(Parent, in this case), correct ?


Me does refer to the current object - the object in question (obj) is a
Child! What you are seeing is overriding working as intended...

--
Larry Lard
Replies to group please

Mar 10 '06 #3
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb
Radu,

An answer from a guy who seldom is beside it in this kind of
questions.

http://groups.google.com/group/micro...7b6507718c418f

I hope this helps,

Cor


Good to have a big archive and somebody who can search it. I would have had
no immediate answer (really). :)
Armin

Mar 10 '06 #4
Thank you all ! It helped !:-)))

Alex.
"Radu" <RE***************************@yahoo.com> wrote in message
news:Zq********************@b2b2c.ca...
Hi. I have the following question:

Since the methods are virtual, the following code produces "Child other
stuff" - the call runs as if pasted in Child... it runs in Parent but in
the context of Child.
-------------------------------
Module Module1

Sub Main()
Dim obj As New Child()
obj.DoSomething()
End Sub

End Module
-------------------------------
Public Class Parent

Public Sub DoSomething()
OtherStuff()
End Sub

Public Overridable Sub OtherStuff()
MsgBox("Parent other stuff")
End Sub

End Class
-------------------------------
Public Class Child
Inherits Parent

Public Overrides Sub OtherStuff()
MsgBox("Child other stuff")
End Sub

End Class
----------------------------------

Therefore, to avoid this, we have to change parent using MYCLASS....

-------------------------------
Public Class Parent

Public Sub DoSomething()
MyClass.OtherStuff()
End Sub

Public Overridable Sub OtherStuff()
MsgBox("Parent other stuff")
End Sub

End Class
-------------------------------

I'm confused as to what exactly is the difference between ME and MYCLASS -
why doesn't ME work in this case ? ME should refer to the current object,
(Parent, in this case), correct ?

Thank you.
Alex.

Mar 10 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Gunnar G | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.