Counting the number of checkboxes...
paulhibbert at mac.com
Sun Apr 20 17:01:53 EDT 2014
Here's another option.
My immediate thought was that this could be a use for an "after mouseUp" handler in a behaviour button, so I tried this…
## Checkbox Behaviour Button Script
## This just loops through the controls on two cards and counts any highlighted checkbox
put 0 into tTotal -- Reset the counter
repeat with x = 1 to the number of controls on card "Card_A"
if the style of control x of card "Card_A" = "checkbox" and \
the hilite of control x of card "Card_A" then add 1 to tTotal
repeat with x = 1 to the number of controls on card "Card_B"
if the style of control x of card "Card_B" = "checkbox" and \
the hilite of control x of card "Card_B" then add 1 to tTotal
put tTotal into fld "countField" of card "Card_A"
-- OR maybe store in a custom property untill needed
…and it does work OK. In this case the count will always be up-to-date with each checkbox change even if the user changes his/her mind and un-checks a previously checked control.
It does mean applying the behaviour to all 28 checkboxes though, but you can do that easily with a repeat script in the multiline message box.
I'm sure there are many other ideas out there.
On 2014-04-20, at 9:18 AM, Charles Szasz <cszasz at me.com> wrote:
> I have 28 checkboxes on two cards. I need to count the total number of checkboxes checked by the user. I have throughout the archives and could not find an example of how to do this. Anybody have a suggestion on how to script this?
> Charles Szasz
> cszasz at mac.com
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the Use-livecode