MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

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


  • Prev by Date: ZTransform for a non-causal unstable signal. How to make Mathematica gives correct result?
  • Next by Date: Re: Title and subtitle on headers of every page in PDF export ?
  • Previous by thread: Dynamically set variable name and value
  • Next by thread: Re: Re: Dynamically set variable name and value