Name
Me Keyword
Syntax
Me
Description
The Me
Keyword represents
the current instance of the class in which code is executing.
Rules at a Glance
Me
is an implicit reference to the current object as defined by theClass...End
Class
statement.Me
is automatically available to every procedure in a VBScript class.
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
Keyword:
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 and Gotchas
Values can’t be assigned to the
Me
Keyword.The
Me
Keyword is particularly useful when passing an instance of the current class as a parameter to a routine outside of the class.
See Also
Get VBScript in a Nutshell, 2nd Edition 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.