April 2002
Intermediate to advanced
688 pages
19h 51m
English
Me Operator
Me
Represents a reference to the current class from within the class
Me is an explicit reference to the current object
as defined by the Class...End
Class construct.
Me corresponds to the C++ this
operator.
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 ModuleThe 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.
Read now
Unlock full access