Design of VBscript class (i)

Source: Internet
Author: User
Tags vbscript class
Should be miles requirements, but also as an example of class design, I put my design date class process out, written this article, for everyone to make a reference. I also hope this article can be a good way for us to write better and more classes. There are countless places in the article, please correct me.
(i) VBScript custom class
Simply put, a class is an object that has properties and methods. Customizing analogy C++,java in VBScript is much simpler. A date class is designed to display the grouped form objects. At the same time, we will explain how to design a custom class.
1, the definition class syntax: Class....end class
Class and End class are used to identify the beginning and ending of a class block, followed by the class name. Now we'll name the date class to be designed as follows: Dateclass syntax:
Class Dateclass
...
End Class
When you use classes in VBScript to create new objects, you can use new operators. For example:
Set Newdate=new Dateclass
2, properties and methods: Private, public and property
Private is used to define variables and functions that can only be accessed within a class; public is used to define the interface of the class, that is, the properties and methods available for external access, which are not members of private and public and are considered public; there and when we have to make the outside accessible, To specify the method of access, however, you would use the Property,property syntax as follows:
Public property [Let|set|get] AA (...)
...
End Property
The property must be used in conjunction with let, set, or get. The description is as follows:
Let set values, such as: user.age=100
Set sets the object, such as: Set User.myobject=nobject
Get take value, such as: Myage=user.age
3, Design date class properties and methods
Now we're going to design the properties of the date class. To display the date, define a classdate to hold the date, its type is public, so that the user can change it outside the class, and then design a function to display the date, named: Datedisplay, type Public, no parameters. The procedure is as follows:
<%
Class Dateclass
Public classdate
Public Function Datedisplay ()
End Function
End Class
%>
4, add the code to display the date
Now we're going to add the Datedisplay code, and the program is as follows:
<%
Class Dateclass
Public classdate
Public Function Datedisplay ()
' If no date is specified, set to current date
If classdate= "" Then
Classdate=now ()
End If
Yy=year (Classdate)
Mm=month (Classdate)
Dd=day (Classdate)
Related Article

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.