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