Normal Topic Calculate and Update Age (Read 3222 times)
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Calculate and Update Age
Feb 23rd, 2004 at 7:01pm
Print Post Print Post  
This code will calculate and update the age.  Age and BirthDate are two LEs in the Form.

In Global Code
===========
stat svAge as String


Subroutine CalculateAge ( )

var vYears as Int
var vMonths as Int
var vDays as Int
var vBirthdate as date = Birthdate
vDays = @date - vBirthdate
vYears = vDays/365.25
vMonths = vDays/30

If vDays >= 365 then  
     {
           svAge = @str (vYears) + " Years"
          If @Int (vYears) = 1 then
           svAge = @Replace (svAge, "Years", "Year")
     }
Else if vDays >= 30 and vDays < 365 then      
     {
           svAge = @str (vMonths) + " Months"
        If @Int (vMonths) = 1 then
           svAge = @Replace (svAge, "Months", "Month")
     }
Else if vDays < 30 then
     {
           svAge = @str (vDays) + " Days"
        If @Int (vDays) = 1 then
           svAge = @Replace (svAge, "Days", "Day")
     }

Age = svAge

End Subroutine


In BirthDate On Element Change Event
=============
      CalculateAge ( )


In BirthDate On Form Entry Event
==============
If not @IsNew and @Update then
      CalculateAge ( )
« Last Edit: Feb 23rd, 2004 at 8:50pm by Bharat_Naik »  
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: Calculate and Update Age
Reply #1 - Feb 23rd, 2004 at 11:36pm
Print Post Print Post  
This is a little more basic then the code above. you can place this in the on element exit of DOB element to  calculate age when entered and also in on form entry of any element to update every time the form is entered.

// calculates age and places it in element named age when exiting  field element  named DOB

if DOB <> ""

     Age = @year(@date)-@year(DOB)-((@month(@date)<@month(DOB))
or (@month (@date) = @month(DOB) and @dom(@date)<@dom(DOB)))

  

Team – Together Everyone Achieves More
Back to top
 
IP Logged