Notifications
Clear all

[Closed] Event handler question…is it possible?

Hi,

see code below, I want to execute cbtn_B1 event handler code when I press button btn_C1, right now it just set the on off state of cbtn_B1 but do not execute any code that is associated with that button. is it possible?

rollout myRollout “R1”
(
checkbutton cbtn_B1 “CheckButton”
button btn_C1 “Button”

on cbtn_B1 changed state do ( if state then (for l in lights do l.ishidden = true) else (for l in lights do l.ishidden = false) )

on btn_C1 pressed do cbtn_B1.state = true

)
createdialog myRollout 100 100

Thanks
Ravi

3 Replies

Hi Ravi, you can take the code in the checkbutton out to a function, then call it from both buttons:

rollout myRollout "R1"
(
    checkbutton cbtn_B1 "CheckButton"
    button btn_C1 "Button"

    function setLightVis bValue =
    (
        if (bValue == true) then
        (
            for l in lights do
                l.ishidden = true
        )
        else
        (
            for l in lights do
                l.ishidden = false
        )        
    )

    on cbtn_B1 changed bState do
    (
        setLightVis bState
    )
    
    on btn_C1 pressed do
    (
        setLightVis true
        cbtn_B1.state = true
    )
)

createdialog myRollout 100 100
  • Enrico
on btn_C1 pressed do cbtn_B1.changed (cbtn_B1.state = true)

The event handler is a function of the control, so you can call it.
Since it expects one argument containing the new state, we pass the new TRUE value as the argument, while at the same time setting the state of the button to the same value.

Thanks Bobo it works!