ش | ی | د | س | چ | پ | ج |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
در زیر کلاس ماژول clsStudent تعریف شده که نمره ای را می گیرد و رتبه ای را بر می گرداند. پراپرتی Let حداقل یک آرگومان می گیرد و الزامیست. با Let یک مقدار به پراپرتی اختصاص یافته همانطور که می ببینید محاسباتی انجام شده و در dblStuMarks قرار داده شده و با Get مقدار این پراپرتی را گرفته یعنی Marks را معادل dblStuMarks قرار داده و این متغیر را در تابع Grade استفاده کرده.
Private dblStuMarks As Double
Public Property Let Marks(iMarks As Double)
dblStuMarks = (iMarks / 80) * 100
End Property
Public Property Get Marks() As Double
Marks = dblStuMarks
End Property
Public Function Grade() As String
Dim strGrade As String
If dblStuMarks >= 80 Then strGrade = "A"
ElseIf dblStuMarks >= 60 Then
strGrade = "B"
ElseIf dblStuMarks >= 40 Then
strGrade = "C"
Else
strGrade = "Fail"
End If
Grade = strGrade
End Function
Sub clsStudentRun()
Dim iStudent As clsStudent
Set iStudent = New clsStudent
'Dim iStudent As New clsStudent
MsgBox iStudent.Marks
MsgBox iStudent.Grade
End Sub
کلاس ماژول تعریف شده یِ زیر
* Property Get. Returns the value of a property.
* Property Let. Assigns a value to the property.
* Property Set. Sets the value of an object property.
پراپرتی Get مقدار پراپرتی را بر می گرداند.
پراپرتی Let یک مقدار به پراپرتی تخصیص می دهد
پراپرتی Set مقدار یک پراپرتی Object را تنظیم می کند
Private employee As Employee
Public Property Get NewEmployee() As Variant
NewEmployee = employee
End Property
Public Property Set NewEmployee(ByVal vNewValue As Employee)
employee = vNewValue
End Property
در زیر دو کلاس ماژول تعریف شده یکی با نام clsCar و دیگری clsMotorCars که مقادیری را می گیرد و محاسباتی را برمی گرداند.
Class Module Named clsCar
Private varCar As clsMotorCars
Public Property Set Car(objCar As clsMotorCara)
Set varCar=objCar
End Property
Public Property Get Car() As MotorCar
Set Car=varCar
End Proprty
Class Module named clsMotorCars
Private strColor As String
Private strName As String
Private dMG As Double
Property Let Color(clr As String)
strColor = clr
End Property
Property Get Color() As String
Color = strColor
End Property
Property Let Name(nm As String)
strName = nm
End Property
Property Get Name() As String
Name = strName
End Property
Property Let Mileage(milesGallon As Double)
dMG = milesGallon
End Property
Property Get Mileage() As Double
Mileage = dMG
End Property
Function FuelBudget(FuelCost As Double, Distance As Double) As Double
FuelBudget = (Distance / Mileage) * FuelCost
End Function
Sub propSetCars()
Dim dDist As Double
Dim dCost As Double
Dim ownCar As clsCar
Set ownCar = New clsCar
Set ownCar.Car = New clsMotorCars
ownCar.Car.Color = "Yellow"
ownCar.Car.Name = "Ford"
ownCar.Car.Mileage = 50
dDist = InputBox("Enter Distance in miles, covered by car in a month")
dCost = InputBox("Enter Cost of Fuel per gallon")
Msgbox ownCar.Car.FuelBudget(dDist, dCost)
End Sub