Average function

Scott Rossi scott at tactilemedia.com
Sun Jan 28 14:36:33 EST 2007


Recently, Tom Vawter wrote:

> The only problem I had was with other
> label fields crashing the party.   I temporarily remedied this by
> putting a 3 in for "number of flds" - mine are fortunately numbered 1 to
> 3.  What I need to know is how to code to restrict the fields considered.

There are several ways to do this.  If the fields checked will always be the
same, you can place their references in a list in the function.  Or you can
build the list as needed and pass the list to the function:

on mouseUp
    put long id of fld 1 & cr & long id of fld 2 & cr & long id of fld 3 \
        into pFieldList
    answer nonemtpyAverage(pFieldList)
end mouseUp


function nonemtpyAverage pFieldList
    put 0 into N
    put 0 into tTotal
    repeat for each line tField in pFieldList
        get value( tField )
        if it <> "" then
            add it to tTotal
            add 1 to N
        end if
    end repeat
    return tTotal/N
end nonemtpyAverage


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