Multiple Captions in Buttons {GBB's Switch workaround}

acron shared this question 9 years ago
Answered

1) visible = true // this is a check box renamed


2) Define a single button1


SetValue[visible,!visible]

SetCaption[button1,If[visible,"Background On","Background Off"]]

This works very well, but...

I would like to have more than two captions in the button...

    SetValue[functUse, functUse+1]

    SetCaption[button2,If[functUse <= 1,"Sine Function","Cosine Function"]]

    SetCaption[button2,If[functUse ≟ 2,"Cosine Function"]]

    SetCaption[button2,If[functUse ≟ 3,"Tangent Function"]]

    SetCaption[button2,If[functUse ≟ 4,"Cotangent Function"]]

    SetCaption[button2,If[functUse ≟ 5,"Secant Function"]]

    SetCaption[button2,If[functUse ≟ 6,"Cosecant Function"]]

I have a slider called functUse which I can increment to the next position, but the Caption does not work properly...


Possibly, I could do it with a list?


Second problem, I need it to revert to the beginning after functUse = 6.


Tony

https://ggbm.at/553667

Comments (5)

photo
1

    SetValue[functUse, Mod[functUse,6]+1]

    SetCaption[button2,Element[{"Sine Function","Cosine function","Tangent Function","Cotangent Function","Secant Function","Cosecant Function"},functUse]]

should do.


Note that SetCaption[button2,If[false,"wheee"]] is equivalent to SetCaption[button2,undefined], which causes the button to lose custom caption and label is used as caption instead.


Cheers,

Zbynek

photo
1

:D :D :D :D :D :D :D :D :D


Thanks, Tony

photo
1

Hi

Otherwise but Kondr has answered before with a more elegante solution in the time I make the answer in this file


https://ggbm.at/553669


Daniel

photo
1

Daniel, the most important line is

    SetValue[functUse, Mod[functUse,6]+1]

. Add this in yours and it works just as well as kondr's.


Tony :wink:

photo
1

Extended kondr's method using a list for the multiple of PI button.


BTW, this method is equivalent to Java's switch statement.


Tony

https://ggbm.at/553673

© 2021 International GeoGebra Institute