Use classes in VBScript (3)

zhaozj2021-02-16  92

Let's analyze the procedures in (2): Class TVProgram

Public StartTime

Publicinal_ProgramDate

Public property Get Programdate, PROGRAMDATE

Programdate = day (internal_programdate) & _

"" & Monthname (Month (Internal_ProgramDate) &_

"" & Year (internal_programdate)

End Property

Public ProgramTITE

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 & "IS on AT" & _

Objtvshow.startTime & "On" & objtvshow.programdate & "."

When calling the object's properties ProgramDate, the function programDate is actually executed, that is, the function as defined above, and soon you will also habred this way to use the public or private keyword in the declaration section. Keyword "Property" tells the compiler to call the function as the call attribute. Then "GET" indicates that the function is the output or a value.

GET means "Allow external code to get 'to get' one value", with its similar keywords, "let" and "set", but these two are more complicated, so we will discuss later.

The next code seems to be a bit difficult, assign the ObjectName.internal_ProgramDate and call it via ObjectName.programDate. If you can use the same keyword to assign it for it and get it, isn't it better? Of course, that can also.

If the names of the get and letas are defined, they can be regarded as the same properties as objects, but they only define the same number of members. (The following code seems not to be the same, only as an example reference) Class TVProgram

Public StartTime

Publicinal_ProgramDate

Public property Get Programdate, PROGRAMDATE

Programdate = day (interNal_programdate) & "_ _

& Monthname (Month (Internal_ProgramDate) &_

"" & Year (internal_programdate)

End Property

Public property let progradate (byval vardatein)

INTERNAL_PROGRAMDATE = CDATE (VARDATEIN)

End Property

Public ProgramTITE

END CLASS

Dim objtvshow

Set objtvshow = new TVprogram

Objtvshow.starttime = cdate ("17:30

")

Objtvshow.programdate = "

17 Sept 99

"

Objtvshow.programtitle = "The Jerry Springer Show"

Response.write objtvshow.programtitle & "IS on AT" & _

Objtvshow.startTime & "On" & objtvshow.programdate & "."

In the above code, the declaration of the declaration seems to be a redundant element. When I first saw it for a long time. Every time I use "0" as a variable to be used in each property, I always get this error message, "The number of elements must be equal." "They are really equal!" After crazy, I went back to see the program and felt my stupid! :) The reason is that when you try to assign a programdate, you will use this line:

Objtvshow.programdate = DTMMYDATE

For convenience, the value of the right side (here, DTMMYDATE) is a function to a function. Therefore, the compiler may think that there is 0 enrollment in Get ProgramDate, and Let Programdate is more! The assigned value is always slightly rejected as the last transior to the attribute, so even if you use other entries, the value is always as the last Cheng Yuan.

Now look at the program. Whether you have a text form via the ProgramDate setting date, it is not a problem with the interNal_ProgramDate to translate the date variable. But can you only use one entry?

If INTERNAL_PROGRAMDATE can only be valid inside, use Let programdate to check the data type of the transfer, we can make a selection. E.g:

Class TVProgram

Public StartTime

PRIVATE INTERNAL_PROGRAMDATE

Public property Get Programdate, PROGRAMDATE

Programdate = day (interNal_programdate) & "" & _

MONTHNAME (Month (Internal_ProgramDate)) & _

"" & Year (internal_programdate)

End Property

Public property let progradate (byval vardatein)

If isdate (Vardatein) THEN

INTERNAL_PROGRAMDATE = VARDATEIN

Else

'Place Some Error Handling Code in Here.

END IF

End Property

Public ProgramTITE

END CLASS

And also declare the StartTime property:

Class TVProgram

PRIVATE INTERNAL_STARTTIME

Public property Get StartTime

StartTime = HOUR (INTERNAL_STARTTIME) & ":" _

& Minute (Internal_StartTime)

End Property

Public property Let StartTime (Byval Vartimein)

If isdate (Vartimein) THEN

INTERNAL_STARTTIME = Vartimein

END IF

End Property

PRIVATE INTERNAL_PROGRAMDATE

Public property Get Programdate, PROGRAMDATE

Programdate = day (interNal_programdate) & "_ _

& Monthname (Month (Internal_ProgramDate) &_

"" & Year (internal_programdate)

End Property

Public property let progradate (byval vardatein)

If isdate (Vardatein) THEN

INTERNAL_PROGRAMDATE = VARDATEIN

END IF

End Property

Public ProgramTITE

END CLASS

... The current code is still not practical from what we want, we will use class TVProgram in other pages, so it is best to independently define it so that all face can be called. We will discuss this in the fourth part.

转载请注明原文地址:https://www.9cbs.com/read-12995.html

New Post(0)