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.