# Use ToExpression[“variablename”] in Slider

I would like to realise something like this (minimial example):

a = 2; b = 3;
Row[{Dynamic@ToExpression[#],
Slider[Dynamic[ToExpression[#]], {1, 5}]}] & /@ {"a", "b"}


But the Slider cannot be moved. However, if I change one of the variables ('a=4') then both is updated. I thought I've seen it before but I cannot find it. I tried localising it (With[...]) but that wasn't succesful. Any ideas?

Perhaps this change?:

Slider[Dynamic[Evaluate@ToExpression[#, StandardForm, Unevaluated]], {1, 5}]...


Dynamic is HoldAll, so it is not passed a symbol unless ToExpression is evaluated first. But simply sticking in Evaluate wouldn't work, because then a and b would continue to evaluate to their numeric values. So you can use the third argument of ToExpression to suspend evaluation.

But @Kuba's suggestion is even more elegant:

Slider[ToExpression[#, StandardForm, Dynamic], {1, 5}]

• or: ToExpression[#, StandardForm, Dynamic] – Kuba Aug 3 '17 at 13:46
• @Kuba Cute. Much nicer. – Michael E2 Aug 3 '17 at 13:48