' Calculate age Public Function CalcAge() As Boolean Dim ldBirth As Date = Date.Now Dim ldBirthAdjusted As Date = Date.Now Dim ldTarget As Date = Nothing Dim ldTemp As Date = Date.Now Dim lnDrop As Integer = 0 ' Reset the values nDay = 0 nMonth = 0 nYear = 0 ' Work with a local variable ldBirthAdjusted = dBirth ldTarget = dTarget ' If the birth date is greater than the target date If dBirth > ldTarget Then ldTemp = ldTarget ldTarget = ldBirthAdjusted ldBirthAdjusted = ldTemp End If Try ldBirth = New Date(ldTarget.Year, ldBirthAdjusted.Month, ldBirthAdjusted.Day) Catch loException As Exception ' If the date cannot be calculated, this is because we have a leap year ldBirth = New Date(ldTarget.Year, 3, 1) ' If we have a leap year If ldTarget.Month > 2 Then lnDrop = 1 End If End Try ' If the birth date is greater than the target date If ldBirth > ldTarget Then nYear = ldTarget.Year - ldBirthAdjusted.Year - 1 Else nYear = ldTarget.Year - ldBirthAdjusted.Year End If ' If the birth date day is greater than the target day If ldBirthAdjusted.Day > ldTarget.Day Then nMonth = (ldTarget.Month - ldBirthAdjusted.Month + 12 - 1) Mod 12 Else nMonth = (ldTarget.Month - ldBirthAdjusted.Month + 12) Mod 12 End If ldTemp = New Date(ldBirthAdjusted.Year + nYear, ldBirthAdjusted.Month, ldBirthAdjusted.Day) nDay = Math.Abs(DateDiff(DateInterval.Day, ldTarget, ldTemp.AddMonths(nMonth))) - lnDrop Return True End Function