Name
Me Operator
Syntax
Me
Description
The Me
operator can represent a class, but only
from within that class.
Rules at a Glance
Me
is an implicit reference to the current object
as defined by the Class...End Class
statement.
Example
In this example, a class method in a WSH script passes an instance of
itself to a function outside of the class by using the
Me
operator:
Dim oCtr Set oCtr = New CCounter oCtr.Increment oCtr.Increment MsgBox "Count: " & oCtr.ShowCount ' definition of CCounter class Class CCounter Private lCtr Property Get Value Value = lCtr End Property Private Sub Class_Initialize( ) lCtr = 1 End Sub Public Sub Increment( ) lCtr = lCtr + 1 End Sub Public Function ShowCount( ) ShowCount = ShowObjectValue(Me) End Function End Class ' Show value of an object's Value property Public Function ShowObjectValue(oObj) ShowObjectValue = oObj.Value End Function
Programming Tips & Gotchas
The
Me
operator can’t be used on the left side of an expression.The
Me
operator is particularly useful when passing an instance of the current class as a parameter.
See Also
Class Statement |
Get VBScript 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.