[Date Index] [Thread Index] [Author Index]
String Input and Variable Setting
Hi, 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 description. 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[ #[], "=\"", #[], "\""]&/@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.