# How to get a useable result from Button [closed]

I want to use Button in a Mathematica CDF for a repeatable action on some lists. So for instance I have the code:

a = {1, 2, 3, 4, 5};
b = Button["x", Print[RandomSample[a]]]


Twice pressing the button gives for instance:

{4,3,2,5,1}
{3,4,2,1,5}


But these two lists turn out to be not real lists. For instance

b[[2]]


does not work. So I am not able to use the result of a button action for further calculations. What am I doing wrong?

Tonight I discovered a nice simple solution for my problem. Here is the code:

SetterBar[Dynamic[x], {1 -> normal, 2 -> random}]
Dynamic[x]
y = Dynamic[
If[x == 1, {1, 2, 3, 4, 5}, RandomSample[{1, 2, 3, 4, 5}]]]


Pushing on "normal" in the setterbar gives the original list {1,2,3,4,5}, pushing on "random" gives each time the list with a new random order. That is exactly what I need.

## closed as off-topic by Alexey Popkov, C. E., m_goldberg, march, MarcoBSep 13 at 12:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Alexey Popkov, C. E., m_goldberg, march, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

• b is the button. If you want the button to set a value for b then do Button["x", b=RandomSample[a]]. You can print if you need it. – Kuba Sep 11 at 15:03
• As the answer is found, I think you may delete this question... – Alexey Popkov Sep 12 at 8:10
• From the Mathematica Documentation ans some experimenting with Button I had come to the conclusion that with Button one could only use something printable. But it turns out one can also get something that is usable for further calculations by making things dynamic, so for instance: – Lau Wachters Sep 13 at 12:32