Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Please explain how to get state of checkbox for its usage in further calculations. And I want to keep the selection from session to session without external savings. Thanks in advance

share|improve this question

1 Answer 1

up vote 8 down vote accepted

You can use DynamicModule.

"Symbols specified in a DynamicModule will by default have their values maintained even across Mathematica sessions." (ref. DynamicModule)

DynamicModule[{x},
 If[ValueQ[reportx], x = reportx, reportx = x = False];
 Checkbox[Dynamic[x, (reportx = x = #) &]], 
 Initialization :> (reportx = x)]

enter image description here

The default value of x/reportx is set to False.

It should only be necessary to evaluate the module once; re-evaluation does not reset anything though.

Note that you will need to keep the checkbox output cell in the notebook since the output is where the dynamic value is held. If you delete the output cell and save the notebook the value of x is gone.

There is an interesting Mathgroup post from John Fultz about that here.

share|improve this answer
    
Recalculation of nb resets value of checkbox –  SergeyFomin Sep 21 '12 at 10:17
1  
Guys from Mars wrote and use this mma, I cant understand anything for two weeks, lets take a pen&paper –  SergeyFomin Sep 21 '12 at 10:56
1  
@ celtschk - I fixed the re-evaluation check. –  Chris Degnen Sep 21 '12 at 11:36
1  
Congratulations!Another pair of shoes!It`s necessary to add this example to poor mma documentation –  SergeyFomin Sep 21 '12 at 12:01
2  
The check against True and False can be replaced with checking ValueQ Which is nicer, since it will work for other dynamic values as well as booleans. –  jVincent Sep 21 '12 at 13:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.