Re: Dynamically set variable name and value
- To: mathgroup at smc.vnet.net
- Subject: [mg108182] Re: Dynamically set variable name and value
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Wed, 10 Mar 2010 01:43:17 -0500 (EST)
- References: <hn5c8h$7nc$1@smc.vnet.net>
Hi, > Hi: I am have some trouble doing something I think should be > relatively direct: > > Take two InputFields: in one place a variable name and in another > place the value you want to set to that variable name. Have the > value assigned to the variable name dynamically update. > > Any help? This should do what you want: DynamicModule[{varname}, Column[{ InputField[Dynamic[varname], String], InputField[ Dynamic[ ToExpression[varname], (Set @@ Append[ToExpression[varname, InputForm, Hold], #]) & ], Number], Dynamic[varname -> ToExpression[varname]] }] ] it is not something that I would recommend, since it will usually fail when not defined _and_ running in the same context. Also I think you are you are asking for problems since the user can create as many variable as he wishes. What is the problem that you try to solve? hth, albert