age calculator
Sarah Reichelt
sarahr at genesearch.com.au
Sun Feb 1 23:11:31 EST 2004
> It wont calculate my age from thease two inputs : date of birth
> 8/2/1961 , assesment date 30/1/2004
Works for me. I get a result of 42 years 11 months 22 days which looks
about right.
>
> and how do parameters work , where does param(1) and param(2) come from
Parameters are the extra bits of information sent to a handler or
function
e.g. answer "Hello"
"Hello" is the parameter.
Usually, the first line of a handler lists what parameters it is going
to get, but if you aren't sure how many you will get, or don't want to
do it this way, you can find the parameters inside your handler using
the param function.
For example, supposing I had a function that multiplied two numbers
together (I know - there is no way you would want to do this, but it
will do for testing)
function doMultiply num1, num2
return num1 * num2
end doMultiply
In the first line, I showed that I was expecting two parameters, which
I was going to label num1 & num2.
The same thing could have been written like this:
function doMultiply
put param(1) into num1
put param(2) into num2
return num1 * num2
end doMultiply
You can also get the parameter count so that we could write this
function to allow for any number of parameters:
function doMultiply
put param(1) into tNum
repeat with x = 2 to paramCount()
multiply tNum by param(x)
end repeat
return tNum
end doMultiply
In this script, both strategies are used, which is not commonly done.
The parameters are labelled initially, but hose labels are never used.
>
> if centurycutoff is set to 35 why does it work for dates from 1970
> onwards only
This is a scripting error. The start & end years are extracted from the
dates, so if you entered 61 and 04, the difference works out as -58.
The difference in years is then correctly calculated from the date
items (which work out the correct years based on the century cutoff)
but the incorrect answer is put into Gbox. Change the 2nd last line to
read "put diffan into Gbox" and it will work.
>
> I am using version RR 1.1.1. (it was a freebie on a magazine) full
> version aparently
I don't see anything in the script that wouldn't work with 1.1.1
>
> oh and one more question please why have a correction and add it to
> item 3 of enddate?
The program gets the days, months & years of each date and subtracts
them giving the difference in days, months & years. If the start date
is the 22nd and the end date is the 4th, then the difference in days is
4 - 22 or -18. To convert this to a positive number, the script
converts the end date from say the 4th April to 34th May - a
nonsensical date, but one which allows the subtraction to work. The
same process is used for months.
>
> many thanks from a novice
>
> Douglas
Cheers,
Sarah
sarahr at genesearch.com.au
http://www.troz.net/Rev/
More information about the use-livecode
mailing list