Introduction to VBS Object-Oriented Programming and Me keyword usage

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.