Return to Snippet

Revision: 48497
at July 3, 2011 05:57 by razmehra


Initial Code
'First: Draw A standard form with 6 text Boxes and  a command 'button:

'TextBox1 (TxtDOB)
'TextBox2 (TxtCurrentDt)
'TextBox3 (TxtLeapDays)
'TextBox4 (TxtAge)
'TextBox5 (TxtAge2)
'TextBox6 (TxtAge3)

'Command Button (Command1) 




Private Sub Command1_Click()
Dim DaysOfMonth(1 To 12) As Integer
Dim CDay, CMonth, CYear, BDay, BMonth, BYear As Integer
On Error Resume Next
CDay = Day(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))
CMonth = Month(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))
CYear = Year(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))
BDay = Day(Format(Me.TxtDOB, "DD/MM/YYYY"))
BMonth = Month(Format(Me.TxtDOB, "DD/MM/YYYY"))
BYear = Year(Format(Me.TxtDOB, "DD/MM/YYYY"))
'DaysOfMonth(1) = 31: DaysOfMonth(2) = 28 + IIf((CYear Mod 4) = 0, 1, 0): DaysOfMonth(3) = 31: DaysOfMonth(4) = 30
DaysOfMonth(1) = 31: DaysOfMonth(2) = 28: DaysOfMonth(3) = 31: DaysOfMonth(4) = 30
DaysOfMonth(5) = 31: DaysOfMonth(6) = 30: DaysOfMonth(7) = 31: DaysOfMonth(8) = 31
DaysOfMonth(9) = 30: DaysOfMonth(10) = 31: DaysOfMonth(11) = 30: DaysOfMonth(12) = 31
SYr = BYear + IIf(BMonth <= 2, 0, 1)
EYr = CYear - IIf(CMonth >= 2, 0, 1)
c = 0
For t = BYear To CYear
  If t Mod 4 = 0 Then c = c + 1
Next
Me.TxtLeapDays = c
If CDay < BDay Then
    CDay = CDay + DaysOfMonth(CMonth): CMonth = CMonth - 1
End If
If CMonth < BMonth Then
    CMonth = CMonth + 12: CYear = CYear - 1
End If
Aday = CDay - BDay: AMonth = CMonth - BMonth: AYear = CYear - BYear
Me.TxtAge = AYear & " Year " & AMonth & " Month " & Aday & " Days"
Me.TxtAge2 = AYear & " Year " & AMonth & " Month " & Aday + c & " Days"

If Aday + c >= DaysOfMonth(Month(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))) Then
    Aday = (Aday + c) - DaysOfMonth(Month(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))): AMonth = AMonth + 1
Else
    Aday = Aday + c
End If
If AMonth >= 12 Then AMonth = 0: AYear = AYear + 1
Me.TxtAge3 = AYear & " Year " & AMonth & " Month " & Aday & " Days"

End Sub

Initial URL

                                

Initial Description
'Normally Peoples get the age of a person in standard 'way(Skipped Leap year's Days)...
'But in my code I'm trying to Getting the Actual Age Included 'Leap Years Days. I don't know I'm right or wrong.. but.. just 'try..

Initial Title
Get purson's Actual Age in MyWay...

Initial Tags

                                

Initial Language
Visual Basic