redefining a variable value
- To: mathgroup at smc.vnet.net
- Subject: [mg48071] redefining a variable value
- From: barrena at ya.com (Manuel Barrena)
- Date: Tue, 11 May 2004 05:19:54 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
I have a button to read an input cell given by a user. This is the cell: Cell[BoxData[ RowBox[{ RowBox[{ StyleBox["answer", Editable->False], StyleBox["=", Editable->False], GridBox[{ {"\[Placeholder]"} }, GridFrame->True, RowLines->True, ColumnLines->True]}], StyleBox[";", Editable->False]}]], "Input", CellTags->"Data entry"] The user just write an integer value in the placeholder. But now, in order to process the user input, the value of "answer" must be not a list but the single integer value. So I need to redefine "answer" to be answer = First[First[answer]]. Of course I do not want to write inside the button function: "answer = First[First[answer]]", because I want to generalize the button to do the same under different variable names (such as "answer", "answer1", "answer2",...), so that I have to select the variable name (in this particular case "answer"), then to read it, then to paste it, and finally to assign the new value (First[First[answer]]). By doing so, the variable "answer" can be processed by another notebook to do the right calculation. This is the goal. Let me explain how I try to reach it and what is the problem I face. I try the following: Clear["Global`*"]; thisnb=EvaluationNotebook[]; NotebookFind[thisnb, "Data entry",All, CellTags]; Set[in, NotebookRead[thisnb]]; (*I need to capture the input cell as it is *) SelectionEvaluate[thisnb, All]; SelectionMove[thisnb, Previous,CellContents]; SelectionMove[thisnb, All, Word]; (*Trying to copy the variable name*) Set[var,NotebookRead[thisnb]]; Now, var contains the word "answer", but it is not editable. For example, if I write: SelectionMove[thisnb, After, Notebook]; NotebookWrite[thisnb, resp, All]; Set[op,Options[NotebookSelection[thisnb]]] I get op = {Editable -> False}, but now if I do: SetOptions[NotebookSelection[thisnb], Editable -> True]; I get an error ("You tried to edit inside a subexpression that cannot be edited, because it is a fixed special form.") My proposal to change the value of the variable answer was finally to write something similar to : NotebookApply[thisnb, "First[First[\[SelectionPlaceholder]]]"]; after selecting the last variable name inside a notebook sentence as answer = answer, but I see that this way is not the proper one. I have two questions: 1. How could I change the option Editable -> False inside the StyleBox? 2. What is the best way to redefine the value of the variable "answer" in the previous example? Thank you very much. Manuel Barrena.