Quote:
Originally Posted by ownedbycats
Should local variables work for check_yes_no?
|
No, not in the way you think. Because check_yes_no() needs the raw value it requires the name of the field, not the value of the field. Thus this will work
Code:
program:
f = '#mybool';
check_yes_no(f, 1, 1, 1)
but this will not. The value is always considered to be undefined.
Code:
program:
f = $#mybool;
check_yes_no(f, 1, 1, 1)
If you want to use a local variable containing a value then you must do something like this:
Code:
program:
# must use raw_field()
f = $$#mybool;
# A bool column fetched with raw_field will have 1 of 3 values, True, False, or None
if f == 'true' then
'yes'
elif f == 'false' then
'no'
elif f == 'none' then
'undefined'
else
'what?'
fi
Another way of saying the above is
Code:
program:
# must use raw_field()
f = $$#mybool;
first_non_empty(
test(f == 'true', 'yes', ''),
test(f == 'false', 'no', ''),
test(f == 'none', 'undefined', '')
)