# Get value of symbol

ab := {{a, 10, 100}, {b, 0, 10}}
Manipulate[a*b, Evaluate[Delete[ab, 0]], Button["SHow", Print[Evaluate[Symbol[ToString[ab[[1]][[1]]]]]]; Print[a, "---", b]]]


In the above example, I am having controls info in a variable ab. Now how to get the value of control variables without directly referring to a and b.

When I clicked the SHow button, I am getting the value if I explicitly print a & b. However I want to get these values using ab.

I tried Evaluate[Symbol[ToString[ab[1][1]]]], but it is not working.

Is there any other simple way?

• It's not clear what you want. What do you want? Where do you want to get the value of the control variables? – Patrick Stevens Oct 29 '15 at 7:04
• @PatrickStevens I want the value of "a" when "SHow" button is clicked . But without explicitly printing "a" – Prashanth Oct 29 '15 at 7:06
• Ah, I see. I think this is nearly a duplicate of mathematica.stackexchange.com/questions/10604/… where the answer is "make a, b parameters of a function instead". – Patrick Stevens Oct 29 '15 at 7:14
• @PatrickStevens thanks for the link. But there is a difference that in my case, I don't know about my control variables explicitly. I have to access it only through "ab". Correct me if I am missing anything – Prashanth Oct 29 '15 at 7:47
• The problem is that a and b are scoped and the full name of each is something like FEa43. – Kuba Oct 29 '15 at 8:10

The problem is that the global symbols hidden in the definition of ab are not localized in the Manipulate. Manipulate reassigns the a and b that appear in the code passed to Manipulate by Evaluate[Delete[ab, 0]] to localized DynamicModule symbols, which are then remapped to front-end dynamic variables whenever the Manipulate output is instantiated in the front end. (It's a complicated process, which you can read about in the four tutorials on Manipulate and dynamic functionality, as well as on this site.)

So one easy way to get the sample code to work the way that is asked is to evaluate ab before it is passed to Manipulate. The OP's ultimate goal seems unclear, not only to me but to some commenters. It is possible that in a more complicated use-case, the following might not work due to reasons specific to the use-case. However, it works on the present example.

ab := {{a, 10, 100}, {b, 0, 10}}
Manipulate[a*b, Evaluate[Delete[ab, 0]],
Evaluate@With[{ab = ab},
Button["SHow", Print[ab[[1, 1]]];
Print[a, "---", b]]
]
]


Update notice: Originally, I had simply modify the Button to remove the Symbol thus: Print[Evaluate[ToString[ab[[1]][[1]]]]. While that was accepted, on second thoughts, I thought printing the actual value instead a string representation seemed more in line with the wording of the question.

• It would be nice to have ParentDynamicModuleNumber[] function finally. – Kuba Oct 30 '15 at 10:36
• @Kuba Wouldn't it though? – Michael E2 Oct 30 '15 at 10:49

You might consider this simple form, which cuts the Gordian knot by making each control show its current value.

ctrls := {{a, 10, 100}, {b, 0, 10}};
Manipulate[a*b,
Evaluate[Sequence @@ (Append[#, Appearance -> "Labeled"] & /@ ctrls)]]


This will work no matter how many controls are specified in the list curls` as long as each element of the list has the proper form.

• Thanks for the answer. But my question is how to get the value after pressing the button. Basically I want to pass the controls' value (value of "a" & "b" in your example) to a function and I am not able to access its value by using controls list (which is "ctrls" in your example) – Prashanth Oct 30 '15 at 0:21