MathGroup Archive 2008

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

Search the Archive

Re: Local variable in ToExpression?

  • To: mathgroup at
  • Subject: [mg85563] Re: Local variable in ToExpression?
  • From: Daniel Huber <dh at>
  • Date: Wed, 13 Feb 2008 07:45:42 -0500 (EST)
  • References: <foudqm$ltq$>

Hi Karl,
note that the local and global result are 2 different variables. Try e.g.:
Module[{result = 3}, result = ToExpression["result=1"]; result]
note that this will set the global result as well.
hope this helps, Daniel

karl.daggfeldt at wrote:
> Hi,
> How can I create a local variable from text in ToExpression?
> test[] := Module[{result = 0}, 
> ToExpression["result=1"]; result]
> test[] will return 0
> How can I make it return 1?
> (here ToExpression is creating a global variable; result=1, even though it is placed inside the Module)
> Sincerely
> Karl Daggfeldt

  • Prev by Date: Re: FindMaximum query
  • Next by Date: Re: RE: Re: How should I start with
  • Previous by thread: Re: Local variable in ToExpression?
  • Next by thread: problem with Inset moving text