How do I get buttons to read from and write to cells?
 First, the cells you read from and write to must be selectable. The cell option CellTags makes this easy to do. The button needs to | | Find the cells to be read. (NotebookLocate, SelectionMove, NotebookFind) |
| | Read in the cells. (NotebookGet, NotebookRead) |
| | Convert the cells into expressions. (MakeExpression, ToExpression) |
| | Manipulate the expressions to create output. |
| | Convert the output into cells. (ToString, MakeBoxes, ToBoxes) |
| | Wite the ouput to the cells. (CellPrint, NotebookWrite, NotebookPut, StylePrint) |
Here is an example. In[1]:= |  |
This function reads in cells with CellTags "x" and "y", converts the cells to values, adds the two values, converts the new value to a cell, and writes out the cell. The following code creates some cells which use this command. In[2]:= |  |
This creates two input cells, a button, and an output cell. If you place a 2 in one input cell, place a 4 in the second input cell, and hit the button, then a six is written to the output cell. Download this FAQ as a Mathematica 5.2 Notebook
Questions or comments? Send email to support@wolfram.com.
| |