The difference between MyClass and Me as it pertains to classes

J

Jay B. Harlow [MVP - Outlook]

Iced Crow,
MyClass refers specifically to the current class. Me refers to the current
object.

For example if I have:

Class BaseClass
Public Overridable Sub f1()
debug.writeline("BaseClass", "f1")
End Sub
End Class

Class Class1 : Inherits BaseClass
Public Sub DoSomething()
MyClass.F1()
Me.F1()
End Sub
Public Overrides Sub f1()
debug.writeline("Class1", "f1")
End Sub
End Class

Class Class2 : Inherits Class1
Public Overrides Sub f1()
debug.writeline("Class2", "f1")
End Sub
End Class

Dim c as New Class2
c.DoSomething()

The call to MyClass.F2 in Class1 will execute Class1.F1 although Class2
overrides it. As MyClass looks specifically at that class.
The call to Me.F2 in Class1 will execute Class2.F1 as Class2 overrides it,
as Me looks at the object itself.

Hope this helps
Jay
 

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