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 mcolProperty_Name As Collection 

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

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

Property - Object

Private mobjProperty_Name As Object 

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

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

Property - Date

Private mdtProperty_Name As Date 

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

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

Property - String

Private mstrPropertyName As String 

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

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

Property - Variant

Private mvarProperty_Name As Variant 

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

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

Property Set Property_Name(rData As Variant)
    Set mvarProperty_Name = rData
End Property

Important

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


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