Name
Me Operator
Syntax
Me
Description
Represents a reference to the current class from within the class
Rules at a Glance
Me
is an explicit reference to the current object as defined by theClass...End
Class
construct.Me
corresponds to the C++this
operator.
Example
In this example, a class passes an instance of itself to a function
outside the class by using the Me
operator.
Private Class CCounter Private lCtr As Long = 1 Public ReadOnly Property Value Get Value = lCtr End Get End Property Public Sub Increment( ) lCtr += 1 End Sub Public Function ShowCount( ) As Long ShowCount = ShowObjectValue(Me) End Function End Class Module modMain Public Sub Main Dim oCtr = New CCounter oCtr.Increment oCtr.Increment MsgBox("Count: " & oCtr.ShowCount) End Sub Public Function ShowObjectValue(oObj As Object) AS Object ShowObjectValue = oObj.Value End Function End Module
Programming Tips and Gotchas
The
Me
operator can’t be used on the left side of an expression.Me
is particularly useful when passing an instance of the current class as a parameter to a routine outside the class.
See Also
Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.