Properties

These are the quantifiable characteristics of an object.
You can find out whether an exception will be generated by looking in the object model documentation.
Property values can be Numerical, String or Boolean and they may be specific or apply to several objects.
They can be obtained or set by assignment statements.
You can easily use the NOT operator to toggle properties on or off. (eg ActiveWindow.DisplayAlerts = NOT ActiveWindow.DisplayAlerts).


Declarations

Also known as property procedures.


Property Get - used to retrieve a property of a class. Get the value of scalar of object property.
Lets you return a property value or property reference
Take action before retrieving
Return a calculated value


Property Let - used to assign the value to a property of a class. Set the value of scalar property.
Lets you define a new property value
Take action after setting
Perform data validation


Property Set - used to assign an object to a property of a class. Set a reference for object property.
Lets you define a new property reference


Property - Collection

Private field_colValue As Collection 

Property Get Property_Name() As Collection
    Set Property_Name = field_colValue
End Property

' You would use Set because Collection is a reference data type
Property Set Property_Name(colData As Collection)
    Set field_colValue = colData
End Property

Property - Object

Private field_oValue As Object 

Property Get Property_Name() As Object
    Set Property_Name = field_oValue
End Property

' You would use Set because Object is a reference data type
Property Set Property_Name(oData As Object)
    Set field_oValue = oData
End Property

Property - Date

Private field_dtValue As Date 

Property Get Property_Name() As Date
    Property_Name = field_dtValue
End Property

' You would use Let because Date is a value data type
Property Let Property_Name(dtData As Date)
    field_dtValue = dtData
End Property

Property - String

Private field_sValue As String 

Property Get PropertyName() As String
    PropertyName = field_sValue
End Property

' You would use Let because String is a value data type
Property Let PropertyName(sData As String)
    field_sValue = sData
End Property

Property - Variant

Private field_vValue As Variant 

Property Get Property_Name() As Variant
    If IsObject(field_vValue) Then
        Set Property_Name = field_vValue
    Else
        Property_Name = field_vValue
    End If
End Property

' You could use either Let or Set
Property Let Property_Name(vData As Variant)
    field_vValue = rData
End Property

Property Set Property_Name(vData As Variant)
    Set field_vValue = vData
End Property

Important

If you are using an Object data type then you must use Set instead of Let.


© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext