O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 the Class...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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required