# Return a local variable from a Module containing a Manipulate

I would like to create a set of custom controls that call Manipulate[] and return the value(s) set during the Manipulate session.

I can easily make a version that uses something like:

MyControl[] := Manipulate[...{a, -10,10}, {b,-1,1}]


This works but variables a, b and any additional variables set by Manipulate are global.

Is it possible to do something like this (Return a Dataset with the selected values for a and b when a "Set" button is clicked and Return Null if "Forget" is clicked):

MyControl[]:= Module[ {a, b},
Manipulate[...{a, -10, 10}, {b, -1, 1},
Button["Set", Return[Dataset[Association @ {aValue->a, bValue->b}]]],
Button["Forget", Return[]]]]


## 1 Answer

Are you certain that a and b in the first example are Global? In version 10 they do not appear to be:

(The sliders of one Manipulate do not affect those of the other.)

A look at the Cell Expression for one of these shows:

. . . DynamicModuleBox[{\$CellContexta$$= -3.3999999999999995, CellContextb$$ =
0.21999999999999997, . . .] . . .


It would seem that these are already localized with DynamicModule.

• Hi Mr. Wizard - I see them as global because I can see the values of a and b from the notebook that calls MyControl[]. I would like a and b to only be visible as a Dataset returned from MyControl[]. I would like a and b to only have definition inside MyControl[]. – Doug Kimzey Sep 3 '14 at 20:52
• I'm using DynamicModule[...] around my Manipulate[] and all Manipulate[] variables are visible and settable in the notebook calling MyControl[]. I have set LocalizeVariables->True and all variables used by Manipulate are visible and settable from the calling notebook. – Doug Kimzey Sep 3 '14 at 21:18