ASP class Properties

Source: Internet
Author: User
Tags end variable


Class Cfoo
Private PVT

' Property Write
Public Property Let PropName (v)
Pvt = V
End Property

' Property Read
Public Property Get PropName ()
PropName = Pvt
End Property
End Class

Dim obj
Set obj = new Cfoo
Obj.propname = "Property value"
Response. Write (obj.propname) ' Show ' property value
Set obj = Nothing

You can see that the property value is equivalent to building a bridge between the private member variable and the outside, so that both parties can communicate with each other.
One would ask, as with a public member variable, what is the independent meaning of its existence?
1. Can perform other functions while assigning value
The following code, which is equivalent to assigning a value of two member variables
Public Property Let PropName (v)
Pvt = V
Another private member variable name = "Pvt value:" & V
End Property
2, can determine the scope of assignment
If the attribute in the example above is read as follows:
Public Property Let PropName (v)
If Len (v) <= 5 Then
Pvt = V
End If
End Property
Executing obj.propname = "Chivan" will not assign a value to pvt successfully because the string is longer than 5.
3, can be set to read-only, write-only properties
As in the example above, if we remove the Let function, the call to Obj.propname = "Property value" is an error, because the function is only readable.



Related Article

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.