Property Let

used to change the (or assign) the value of a class property.
This statement lets you define a procedure that assigns a value to a property.
If you want to have full control when a property is initialised you can define the property using a Property Let procedure.

Public Property Let Property_One() 
End Property

Passing Parameters

It is possible to pass parameters although not best practice.


Department

Public Property Let Property_Department(sDepartment As String) 
     If (sDepartment <> "Sales") And (sDepartment <> "Research") Then
         Err.Raise "This is not a valid department name"
         Exit Property
     End If
     
     field_sDepartment = sDepartment
End Property

The following line assigns a department by calling the Property Let procedure

objEmployee.Property_Department = "Sales" 

Hours Per Week

Public Property Let Property_HoursPerWeek(dbHoursPerWeek As Double) 
   field_dbNormalHours = WorksheetFunction.Min(35, field_dbHoursPerWeek)
   field_dbOvertimeHours = WorksheetFunction.Max(0, field_dbHoursPerWeek - 35)
End Property

Write Only Properties

These are not used very often but it is possible to create jus a write-only property
Just provide a property let procedure (no property set)


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