[Closed] toggling checkboxes
this is probably really simple, but is driving me nuts:
I have seven checkboxes in a row (ckb4…ckb10) and want them toggled so that only one can be checked at a time.
I thought that I could use a loop and index with an execute command to slip the index into the button state using the event handler:
on ckb7 changed arg do
(AVR_viewbuttons 7 arg)
fn AVR_viewbuttons butNo arg=
(
--make sure that only one is checked at a time
print butNo
for i = 4 to 10 do
(
--if it's checked
if arg == true then
(
if i != butNo do
(
execute ("AVR_Tools.ckb"+(i as string)+".checked = false")
)
)
--if its unchecked
else
(
--do something else here
)
)
It keeps checking all of them so I guess that the i != butNo test is failing, but I can’t see how – must be the clocks going back or something!
Hi Alex,
I’d stay away from “execute” statement with a little more scripting and maybe less neat code.
You can write a function called on checking event of each checkBox, passing an index as argument on checking, and something else, like a 0, on unchecking.
The function could at first uncheck every checkBox, then in a Case Expression could recheck the desired checkBox specified through the argument, or nothing if the 0 is passed.
It’s not the answer to your question, but I hope this helps.
- Enrico
Hi Alex,
Glad you solved the issue. However, I was thinking a mapped function could simplify this operation. By storing the checkboxes in a temporary array you could pass this and the checkbox to the mapped function. It could then compare when it is looping if it is the checkbox that was passed, set it to true. If not, it sets it to false. A bit like how radio buttons work!
rollout CheckIt "" width:258 height:34
(
mapped function CheckState ChkCtrls Chkbox = (if ChkCtrls == chkbox then ChkCtrls.checked = true else ChkCtrls.checked = false)
checkbox chk4 "4" pos:[8,9] width:28 height:16
checkbox chk5 "5" pos:[44,9] width:28 height:16
checkbox chk6 "6" pos:[76,9] width:28 height:16
checkbox chk7 "7" pos:[112,9] width:28 height:16
checkbox chk8 "8" pos:[147,9] width:28 height:16
checkbox chk9 "9" pos:[183,9] width:28 height:16
checkbox chk10 "10" pos:[215,9] width:38 height:16
on CheckIt open do checkUI = #(chk4,chk5,chk6,chk7,chk8,chk9,chk10)
on chk4 changed arg do checkstate checkUI chk4
on chk5 changed arg do checkstate checkUI chk5
on chk6 changed arg do checkstate checkUI chk6
on chk7 changed arg do checkstate checkUI chk7
on chk8 changed arg do checkstate checkUI chk8
on chk9 changed arg do checkstate checkUI chk9
on chk10 changed arg do checkstate checkUI chk10
)
createdialog checkit
and all without having to use execute
Maybe try the controls array of a rollout?
global rolloutname
– in the rollout
on chb changed state do
(
for i in rolloutname.controls where matchString i.name “somename” do
if i.state == state and i.name != chb.name then i.state = not state
)
I haven’t tested it, but you get the idea.
-Johan
ah that might be because they were checkbuttons not checkboxes…getting late in the day sorry guys