کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی
کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی

نوشتن کلاس ماژول



Private varPropertyName As Variant 

Property Get PropertyName() As Variant 
    If IsObject(varPropertyName) Then 
        Set PropertyName = varPropertyName 
    Else 
        PropertyName = varPropertyName 
    End If 
End Property 


Property Set PropertyName(rData As Variant) 
    Set varPropertyName = rData 
End Property 





در زیر کلاس ماژول 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














نظرات 0 + ارسال نظر
برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد