Using classes in VBScript (iii)

Source: Internet
Author: User
Tags date define end variable
Vbscript|vbscript us to analyze the program in (2):

Class Tvprogram

Public StartTime



Public internal_programdate



Public Property Get Programdate

Programdate = Day (internal_programdate) & _

"" & MonthName (Month (internal_programdate)) & _

"" & Year (Internal_programdate)

End Property



Public Programtitle

End Class



Dim Objtvshow

Set objtvshow = New Tvprogram



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

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

Objtvshow.programtitle = "The Jerry Springer Show"





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

Objtvshow.starttime & "On" & Objtvshow.programdate & "."



When you call the object's property programdate, you actually perform the function programdate, which is the function defined on it, and soon you will also get used to the way the public or private keyword is used in the declaration section. The keyword "Property" tells the compiler to call the function externally, as it would call the attribute. The next "Get" indicates whether the function is an output or a value.

Get means "Allow external code to ' fetch ' a value ' and its similar keyword has" let "and" Set ", but these two are more complicated, so we'll discuss it later.

The next code looks a bit difficult, assigning a value to objectname.internal_programdate and calling it through Objectname.programdate. Wouldn't it be better if you could use the same keyword to assign a value to it and get its value? Of course, that's OK.

If you define the same names for the Get and let properties, you can treat them as objects with the same properties, but only if they define the same number of members. (The following code appears to be different, only as an instance reference)

Class Tvprogram

Public StartTime



Public internal_programdate



Public Property Get Programdate

Programdate = Day (internal_programdate) & "" _

& MonthName (Month (internal_programdate)) & _

"" & Year (Internal_programdate)

End Property



Public Property Let Programdate (ByVal Vardatein)

Internal_programdate = CDate (Vardatein)

End Property



Public Programtitle

End Class



Dim Objtvshow

Set objtvshow = New Tvprogram



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

Objtvshow.programdate = "Sept 99"

Objtvshow.programtitle = "The Jerry Springer Show"

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

Objtvshow.starttime & "On" & Objtvshow.programdate & "."



The Let's declaration section in the above code appears to be an extra element that I studied for a long time when I first saw it. Every time I use "0" as a variable on each attribute, I always get this error message, "the number of elements must be equal." "They are indeed equal!" After being mad, I looked back at the program before I felt stupid! :)

The reason is that when you try to assign a value to a programdate, you use one line of programs:

Objtvshow.programdate = Dtmmydate

For convenience, the value to the right of the equal sign (here refers to dtmmydate) as a Cheng gives the function. So the compiler may think that there are 0 programdate in the GET, and let Programdate is one more! The assigned value is always skipped and used as the last pass of the attribute, so even if you use a different element, the assigned value is always the last one.

Now look at the program. Regardless of whether the date is formatted as text by programdate or translated into a date variable with internal_programdate, the program has no problem. But can not only use one entrance?

If internal_programdate can only be valid internally, and we use let programdate to check the data type of the transmission, we can make a choice. For example:

Class Tvprogram

Public StartTime



Private internal_programdate



[1] [2] Next page



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.