Good afternoon everyone,
I could really use some help and I’m sure for most of you this is a simple piece of coding.
Basically, I want a count of 1 for every check box that is not blank and the total added together that I'm going to put in a data display. The closest I’ve come this morning is below and it only works if none of the check boxes are left blank. I’m sure there is a much easier – and right – way to do it.
Any help is, as always, greatly appreciated.
{fn count(a, b, c, d) {
local e = 0
local f = 0
local g = 0
local h = 0
if a <> "" then
e = 1
if b <> "" then
f = 1
if c <> "" then
g = 1
if d <> "" then
h= 1
endif endif endif endif
return (e + f + g + h)
}}
The problem you had is if a is blank then the function exits the 'if' statement. Do it like below and it should work for you
{fn count(a, b, c, d) {
local e = 0
local f = 0
local g = 0
local h = 0
if a <> "" then
e = 1
endif
if b <> "" then
f = 1
endif
if c <> "" then
g = 1
endif
if d <> "" then
h= 1
endif
return (e + f + g + h)
}}
That worked perfectly.
Thanks for your help!
simpler, less redundant use of local variables:
fn count(a,b){
local total = 0
if(a<>0)then
total = total +1
endif
if(b<>0)then
total = total + 1
endif
return total
}