Average function

Scott Rossi scott at tactilemedia.com
Sun Jan 28 13:19:19 EST 2007


Recently, Tom Vawter wrote:

> Is there an average function that will not consider blank fields?  For
> instance, if I have 10 and 8 in two fields and an empty third field, I
> want to take the average of the numbers in the three fields and get 9
> rather than 6.

Could you do this?

 function nonemtpyAverage
    put 0 into N
    put 0 into tTotal
    repeat with F = 1 to number of flds
       add fld F to tTotal
       if fld F <> "" then add 1 to N
    end repeat
    return tTotal/N
 end nonemtpyAverage

You may need to limit the number of fields you want to check.

Regards,

Scott Rossi
Creative Director
Tactile Media, Multimedia & Design
-----
E: scott at tactilemedia.com
W: http://www.tactilemedia.com





More information about the use-livecode mailing list