![]() ![]() | ||
As discussed in the In Depth section of this chapter, you often don't want to give code outside an object direct access to the data in the object. Instead, you can use properties, which use methods to set or get an internal value. We saw how to do that in Chapter 3; here's an example from that chapter where I'm adding a property to a module:
Module Module2 Private PropertyValue As String Public Property Prop1() As String Get Return PropertyValue End Get Set(ByVal Value As String) PropertyValue = Value End Set End Property End Module
See the topic "Creating Properties" in Chapter 3 for all the details, including how to create indexed properties. Note that you can make properties write-only with the WriteOnly keyword (and you must omit the Get method):
Module Module2 Private PropertyValue As String Public WriteOnly Property Prop1() As String Set(ByVal Value As String) PropertyValue = Value End Set End Property End Module
You can make properties read-only with the ReadOnly keyword (and you must omit the Set method):
Module Module2
Private PropertyValue As String
Public ReadOnly Property Prop1() As String
Get
Return PropertyValue
End Get
End Property
End Module
Related solution: |
Found on page: |
---|---|
132 |
![]() ![]() | ||