Me Operator

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

MyClass Keyword

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net