Get purson's Actual Age in MyWay...


/ Published in: Visual Basic
Save to your folder(s)

'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..


Copy this code and paste it in your HTML
  1. 'First: Draw A standard form with 6 text Boxes and a command 'button:
  2.  
  3. 'TextBox1 (TxtDOB)
  4. 'TextBox2 (TxtCurrentDt)
  5. 'TextBox3 (TxtLeapDays)
  6. 'TextBox4 (TxtAge)
  7. 'TextBox5 (TxtAge2)
  8. 'TextBox6 (TxtAge3)
  9.  
  10. 'Command Button (Command1)
  11.  
  12.  
  13.  
  14.  
  15. Private Sub Command1_Click()
  16. Dim DaysOfMonth(1 To 12) As Integer
  17. Dim CDay, CMonth, CYear, BDay, BMonth, BYear As Integer
  18. On Error Resume Next
  19. CDay = Day(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))
  20. CMonth = Month(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))
  21. CYear = Year(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))
  22. BDay = Day(Format(Me.TxtDOB, "DD/MM/YYYY"))
  23. BMonth = Month(Format(Me.TxtDOB, "DD/MM/YYYY"))
  24. BYear = Year(Format(Me.TxtDOB, "DD/MM/YYYY"))
  25. 'DaysOfMonth(1) = 31: DaysOfMonth(2) = 28 + IIf((CYear Mod 4) = 0, 1, 0): DaysOfMonth(3) = 31: DaysOfMonth(4) = 30
  26. DaysOfMonth(1) = 31: DaysOfMonth(2) = 28: DaysOfMonth(3) = 31: DaysOfMonth(4) = 30
  27. DaysOfMonth(5) = 31: DaysOfMonth(6) = 30: DaysOfMonth(7) = 31: DaysOfMonth(8) = 31
  28. DaysOfMonth(9) = 30: DaysOfMonth(10) = 31: DaysOfMonth(11) = 30: DaysOfMonth(12) = 31
  29. SYr = BYear + IIf(BMonth <= 2, 0, 1)
  30. EYr = CYear - IIf(CMonth >= 2, 0, 1)
  31. c = 0
  32. For t = BYear To CYear
  33. If t Mod 4 = 0 Then c = c + 1
  34. Next
  35. Me.TxtLeapDays = c
  36. If CDay < BDay Then
  37. CDay = CDay + DaysOfMonth(CMonth): CMonth = CMonth - 1
  38. End If
  39. If CMonth < BMonth Then
  40. CMonth = CMonth + 12: CYear = CYear - 1
  41. End If
  42. Aday = CDay - BDay: AMonth = CMonth - BMonth: AYear = CYear - BYear
  43. Me.TxtAge = AYear & " Year " & AMonth & " Month " & Aday & " Days"
  44. Me.TxtAge2 = AYear & " Year " & AMonth & " Month " & Aday + c & " Days"
  45.  
  46. If Aday + c >= DaysOfMonth(Month(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))) Then
  47. Aday = (Aday + c) - DaysOfMonth(Month(Format(Me.TxtCurrentDt, "DD/MM/YYYY"))): AMonth = AMonth + 1
  48. Else
  49. Aday = Aday + c
  50. End If
  51. If AMonth >= 12 Then AMonth = 0: AYear = AYear + 1
  52. Me.TxtAge3 = AYear & " Year " & AMonth & " Month " & Aday & " Days"
  53.  
  54. End Sub

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.