Example - Employee


class_Employee

Lets create a simple class based on an employee to illustrate how to use classes.
First you would insert a class module called "class_Employee" with the following code.
This Employee class will define a single, generic, employee.

Private field_sName As String 
Private field_sDescription As String
Private field_dbHourlyRate As Double
Private field_sngHoursPerWeek As Single

Property Get Property_Name() As String
    Property_Name = field_sName
End Property
Property Let Property_Name(ByVal sName As String)
    field_sName = sName
End Property

Property Get Property_Department() As String
    Property_Department = field_sDescription
End Property
Property Let Property_Department(ByVal sDescription As String)
   field_sDescription = sDescription
End Property

Property Get Property_HourlyRate() As Double
   Property_HourlyRate = field_dbHourlyRate
End Property
Property Let Property_HourlyRate(ByVal dbHourlyRate As Double)
   field_dbHourlyRate = dbHourlyRate
End Property

Property Get Property_HoursPerWeek() As Single
   Property_HoursPerWeek = field_sngHoursPerWeek
End Property
Property Let Property_HoursPerWeek(ByVal sngHoursPerWeek As Single)
   field_sngHoursPerWeek = sngHoursPerWeek
End Property

Public Function Method_WeeklyPay() As Double
   Method_WeeklyPay = (field_dbHourlyRate * field_sngHoursPerWeek)
End Function

Insert a standard module with the following code/subroutine.
To work with one particular employee, you just call the properties and methods for that employee.

Public Sub TestingClassEmployee() 
   Dim oEmployee As class_Employee

   Set oEmployee = New class_Employee
   oEmployee.Property_Name = "Richard"
   oEmployee.Property_Department = "Sales"
   oEmployee.Property_HourlyRate = 12.75
   oEmployee.Property_HoursPerWeek = 35
   Call MsgBox(oEmployee.Property_Name & " earns £" & oEmployee.Method_WeeklyPay() & " a week")

   Set oEmployee = Nothing
End Sub


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