Tip

Age Computation

This function takes two inputs: a string representation of the date of birth
and the uidoc where the field is located. In this example, age is the name of
the target field.
The function does return an integer value, so it can be accessed readily
through the following call:
age = getage(dob$, uidoc)
To use the code, just paste it in after the End Sub line of the calling script,
or tailor as you wish through script libraries.

If you have questions or problems, please feel free to contact me.
Function getage(temp_dob As String, uidoc As notesuidocument) As Integer

Dim message As String
Dim timenow As Variant
Dim dyear As Integer, nyear As Integer, dmonth As Integer, nmonth As Integer,
dday As Integer, nday As Integer
Dim age As Integer

'initialize values
Dim dob As Variant
dob = Datevalue(temp_dob)
timenow = Date
dyear = Year(dob)
nyear = Year(timenow)
dmonth = Month(dob)
nmonth = Month(timenow)
dday = Day(dob)
nday = Day(timenow)
If nmonth > dmonth Then
age = nyear - dyear
Elseif nmonth < dmonth Then
age = nyear - dyear - 1
Elseif nmonth = dmonth Then
If nday > dday Then
age = nyear - dyear
Elseif nday < dday Then
age = nyear - dyear - 1
Elseif dday = nday Then
age = nyear - dyear
End If
Else
message = "Unable to compute the person's age. Please enter it below."
age = Cint(Inputbox(message))
End If
Call uidoc.fieldsettext("Age",Cstr(age))
'doc.Age = Cstr(age)
'Call doc.save(True, True)
getage = Cint(age)
End Function

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.