Design of VBscript class (II.)

Source: Internet
Author: User
Tags vbscript class
Busy looking for a job until the weekend is free. Now to continue the design of our VBScript class. We've designed a simple date class the last time, but there are some
On the issue. Now we're going to change our design for these issues. The problem we have to solve this time is:
1, if the user specified classdate is not a date type, then the date will become January 1, 1900;
2. If more than one date is displayed, the name of the form object cannot be the same;
3, the best to add CSS;
The following are discussed separately
First, in the last time we designed the DataClass, we defined a public variable classdate to represent the date, and the user is free to classdate values and
Read, which makes it impossible to tell if the user is assigning the correct value. Now we change the redefinition of a variable cldate to private so that the user cannot access the Cldate directly
Out. As follows:
Private Cldate
In order to allow users to access the Classdate, the last mention of the property, now we use it to construct two functions, one is to allow users to classdate
The function to assign a value, called Classdate. The definition is as follows:
Pbulic Property Let Classdate (FDate)
...
End Property
Another function is to have the user read the cldate, defined as follows:
Public Property Get Classdate ()
...
End Property
Well, after the definition of a function, you can write code, in let Classdate, mainly to determine the user input is not the date type, as follows:
Public Property Let Classdate (FDate)
If TypeName (fdate) = "Date" Then
Cldate=fdate
End If
End Property
In Get Classdate, the main is to assign the value of Cldate to the function: as follows:
Public Property Get Classdate ()
Classdate=cldate
End Property

What if you don't assign a value to Clname? That is, when this class is just generated, clname is a null value, and here is an introduction to the automatic process of class initialization and termination: clas_initialize
and Class_Terminate. The first process is performed automatically in the generated class, and the second is automatically executed when the class is eliminated. The first process is used here. As follows:
Private Sub Class_Initialize ()
Cldate=now ()
End Private
Thus, when a class is generated, if the clname is not assigned a value, then Clname is the current date.
Second, in order to display multiple dates in the form, we have to distinguish each generated date object, that is, to name. Here we define a variable clname of the private type to
Defines the name of the form control that is generated. The definition is as follows:
Private Clname
Similarly, to allow users access to clname variables, you also define two functions, the same method as Classdate. The code is as follows:

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.