MathGroup Archive 2006

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

Search the Archive

String Input and Variable Setting

  • To: mathgroup at
  • Subject: [mg64094] String Input and Variable Setting
  • From: ggroup at
  • Date: Wed, 1 Feb 2006 04:34:26 -0500 (EST)
  • Sender: owner-wri-mathgroup at


I am setting up a notebook that needs to be easy to use and readable by
people who are essentially completely unfamiliar with Mathematica (ie I
like to hide the code as much as possible, and I like to write things
in as flexible/general a manner as I can).  The user needs to input
some information before running the notebook, so I've placed a table
(Input->Create Table/Matrix/Palette...) in one of the first sections.
I want this table to have one column for the variable name, a second
column for the user's input value, and the third column for a short

Now I want to assign the user's value (column 2) to the appropriate
variable (column 1).    Is there a fairly foolproof method?  In
general, column 2 will contain an arbitrary string value.

My current approach is to have the user enter everything as strings.
Then, to avoid errors, I construct the assignment expressions
explicitly.  So, for example, suppose I assign the input table to the
variable called header, then my code looks something like:

header = <some table of strings>;
ToExpression[ StringJoin[ #[[1]], "=\"", #[[2]], "\""]&/@header

This seems to be fairly robust (ie I haven't thought of an exception
where this wouldn't work as expected), but is there a better way to do
this in general?  Also, is there a way to suppress the quote marks in
the input table, but still have all entries treated as literal strings?

Thanks very much.

  • Prev by Date: Re: Getting the value of the independent var from the dep.var using NDSolve
  • Next by Date: Re: Trying to animate the rotation of a plane about an axis using dynamic visualizer - MoviePlot3D.nb (0/1)
  • Previous by thread: Re: Getting the value of the independent var from the dep.var using NDSolve
  • Next by thread: Re: String Input and Variable Setting