Option Explicit

Dim Employee As clsEmployee

Sub EmpPay()

Set Employee = New clsEmployee

With Employee

.EmpName = "Tracy Syrstad" .EmpID = "1651" .EmpRate = 25 .EmpWeeklyHrs = 40

MsgBox .EmpName & " earns $" & .EmpWeeklyPay & " per week." End With

End Sub

The sub procedure declares an object Employee as a new instance of clsEmployee. It then assigns values to the four properties of the object and generates a message box displaying the employee name and weekly pay (see Figure 20.7). The object's method, EmpWeeklyPay, is used to generate the displayed pay.

Figure 20.7

Create custom objects to make code more efficient.

Tracy Syrslad earns i1000 per week-OK I

0 0

Post a comment