newbie requires help

Rob Cozens rcozens at pon.net
Sun Jan 25 10:21:55 EST 2004


>I downloaded the age calculator on from the web. It comes p 
>continually with the same "bug" i dont know how to fix.

Hi Douglas,

I'm too lazy to track through the logic to find the bug; but here's a 
handler that works for me:

on showAge
   ask "Enter Date of Birth in system date format..."
   if it is empty then exit showAge
   put it into firstDate
   /*  I would validate the date using Serendipity Library's validDate function
	rather than use the line above

   if validDate(it) then put it into firstDate
   else
     beep
     answer "The birth date you entered is not a valid date!"
     exit showAge
   end if
   */
   ask "Enter Date of Assessment in system date format" with the short 
system date
   if it is empty then exit showAge
   put it into secondDate
   /*  I would validate the date using Serendipity Library's validDate function
	rather than use the line above

   if validDate(it) then put it into secondDate
   else
     beep
     answer "The assessment date you entered is not a valid date!"
     exit showAge
   end if
   */
   convert firstDate to dateItems
   convert secondDate to dateItems
   if secondDate < firstDate then
     beep
     answer "The subject was born after the assessment date!"
     exit showAge
   end if
   put (item 1 of secondDate)-(item 1 of firstDate) into yearsOld
   put (item 2 of secondDate)-(item 2 of firstDate) into monthsOld
   put (item 3 of secondDate)-(item 3 of firstDate) into daysOld
   if daysOld < 0 then
     put abs(daysOld) into daysOld
     subtract 1 from monthsOld
   end if
   if monthsOld < 0 then
     add 12 to monthsOld
     subtract 1 from yearsOld
   end if
   if yearsOld = 1 then put empty into lastYearCharacter else put "s" 
into lastYearCharacter
   if monthsOld = 1 then put empty into lastMonthCharacter else put 
"s" into lastMonthCharacter
   if daysOld = 1 then put empty into lastDayCharacter else put "s" 
into lastDayCharacter
   answer "Subject 
is"&&yearsOld&&"year"&lastYearCharacter&","&&monthsOld&&"month"&lastMonthCharacter&", 
and" \
       &daysOld&&"day"&lastDayCharacter&&"old."
end showAge
-- 

Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.net/who.htm

"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."

from "The Triple Foole" by John Donne (1572-1631)


More information about the use-livecode mailing list