Re: StringInput Question
- To: mathgroup at smc.vnet.net
- Subject: [mg83519] Re: StringInput Question
- From: David Reiss <dbreiss at gmail.com>
- Date: Thu, 22 Nov 2007 04:42:40 -0500 (EST)
- References: <fi0p1j$67m$1@smc.vnet.net>
First off, the use of FrontEndExecute here is moot. Unless each of the function calls within FrontEndExecute are in the FrontEnd` context they will be sent to the Kernel. So let's remove the call to FrontEndExecute. Also use of Module removes the need to use the two Clear Statements. Also you probably want to use InputNotebook rather than SelectedNotebook Also I will make this all somewhat more Mathematica 6-ish. But the key thing that you are wanting to do is to catch when $Canceled is generated. Simply use an If statement as in the following Button["TEST", Module[{content, nb}, content = InputString["New Tag"]; nb = InputNotebook[]; If[content =!= $Canceled, NotebookWrite[nb, Cell[content, "Text"]] ] ], Method -> "Queued" ] Note the Method -> "Queued" option. This approach has problems if the default Method -> "Preemptive" option is used. I hope that this helps... -David A WorkLife FrameWork E x t e n d i n g MATHEMATICA's Reach... http://scientificarts.com/worklife/ On Nov 21, 3:08 am, Joe Sneed <jsn... at mines.edu> wrote: > The following is is a test for a button that prompts for inputting a > string to be written to a notebook. > > *Cell[BoxData[ > ButtonBox["TEST", > Active->True, > BaseStyle->"Paste", > ButtonFunction:> > FrontEndExecute[{ > content = > InputString["New Tag"]; > nb = SelectedNotebook[]; > NotebookWrite[nb, > Cell[content, "Text"]]; > Clear[content]; > Clear[nb]}], > Evaluator-> > "Local"]], "Text", > FontFamily->"Arial",* > *FontWeight->"Bold"]* > > Run in V6.01, when the dialog box for StringInput is closed without > input, the string > > $Canceled > > is written to the selected notebook. > > The desired behavior (which I think occurred in V5.01, though I have no > easy way to check now) is that when the dialog box for StringInput is > closed without input, nothing is written. How can this be obtained with > V6.01? > > Any help much appreciated. > > Joe Sneed > > -- > Joe Sneed > Division of Liberal Arts and International Studies > Colorado School of Mines > Golden CO USA > mailto:jsn... at mines.eduhttp://www.mines.edu/fs_home/jsneed/