53 lines
1.2 KiB
VB.net

' Age Class To Generate Age From Date Of Birth
Public Class age
Private _days As Integer
Private _monthes As Integer
Private _years As Integer
Private _birthdate As Date
Public Sub New(Birthdate As Date)
_birthdate = Birthdate
Calculate(Birthdate)
End Sub
ReadOnly Property Birthdate As Date
Get
Return _birthdate
End Get
End Property
ReadOnly Property Years As Integer
Get
Return _years
End Get
End Property
ReadOnly Property Monthes As Integer
Get
Return _monthes
End Get
End Property
ReadOnly Property Days As Integer
Get
Return _days
End Get
End Property
ReadOnly Property Printable As String
Get
Return "You Are " & _years & " Years " & _monthes & " Monthes " & _days & " Old"
End Get
End Property
Private Sub Calculate(Birthdate As Date)
' Breaking Down The Date Difference Into Year, Monthes and Days
_years = DateDiff(DateInterval.Year, Birthdate, Now)
_monthes = DateDiff(DateInterval.Month, Birthdate, Now) Mod 12
_days = DateDiff(DateInterval.Day, Birthdate, Now) Mod 30 - 10
End Sub
End Class