Using classes in VBScript (ii)

Source: Internet
Author: User

Creating objects

When you create an object type (Class) in VBScript, you first have to know that it's really easy! I self-study in an afternoon, just read the Microsof VB Script reference book, but must admit that this book is not the easiest document to read.

Beginners need to install the VBScript 5.0 engine, which can be downloaded at the Microsoft ' s scripting site.

Let's look at the code. The definition of a class is very similar to a function and a child procedure. The Start behavior class <myclassname>, ending with End class, all object definitions written in the intermediary department. Now we can build the first class with what we've learned and not implement any functional classes.

Class 4GuysTestObject

End Class

This doesn't seem to be the case, but when you write the following code, you create an instance of the object:

Dim Objtestobject

Set Objtestobject = New 4GuysTestObject

Set Objtestobject = Nothing

Obviously, we can't do anything with objects right now, and now I'm going to explain how to define properties and methods in the object.

The most basic thing you can do with an object is to create a set of data. For example, if you want to set up a time, date, and video program title, you can create an object that contains the attributes "StartTime", "Programdate", and "Programtitle". The code is as follows:

Class Tvprogram

Public StartTime

Public programdate

Public Programtitle

End Class

Dim Objtvshow

Set objtvshow = New Tvprogram

Objtvshow.starttime = CDate ("17:30")

Objtvshow.programdate = DateSerial (1999,9,17)

Objtvshow.programtitle = "The Jerry Springer Show"

Response.Write Objtvshow.programtitle & "are on" & _

Objtvshow.starttime & "on" & Objtvshow.programdate

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.