VBS is a very simple scripting language. Because it is simple, it only supports a small part of the object-oriented features.
Other object-oriented programming languages usually use the this or self keyword to access the current object, while VBS uses the Me keyword. The Me keyword indicates the current instance of the class during code execution, or the current object ).
An object is an instance of a class. The same class can instantiate many objects with the same attributes and methods, but each object is unique and their member variables are not the same. These member variables are accessed through object references. Outside the class, each object is identified by a variable that stores the object reference. Inside the class, this variable cannot be accessed, however, VBScript internally tracks the attributes or methods of the class being executed by an object and obtains the information through the Me keyword.
A simple class:Copy codeThe Code is as follows: Class myClass
Private I _count
Public Property Get count
Count = I _count
End Property
Public Property Let count (c)
I _count = c
End Property
End Class
In this example, a private variable is declared, which can be referenced inside the class. However, sometimes, when we access a variable, we want a piece of code to be executed.
Use the Me Keyword:Copy codeThe Code is as follows: Class myClass
Private I _count
Public Property Get count
I _count = I _count + 1
Count = I _count
End Property
'Demon note:
'Actually, this is purely for the use of Me.
'Direct countTwice = count + count is simpler
Public Property Get countTwice
CountTwice = Me. count + Me. count
End Property
Public Property Let count (c)
I _count = c
End Property
End Class
In this example, each time you access the count attribute, it is added with 1.
Reference link:Self-referencing in VBScript
Reference link:VbScript Me Keyword
Original article: http://demon.tw/programming/vbs-me-keyword.html