MathGroup Archive 2007

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

Search the Archive

Re: StringInput Question

  • To: mathgroup at
  • Subject: [mg83519] Re: StringInput Question
  • From: David Reiss <dbreiss at>
  • Date: Thu, 22 Nov 2007 04:42:40 -0500 (EST)
  • References: <fi0p1j$67m$>

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


 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...

A WorkLife FrameWork
E x t e n d i n g MATHEMATICA's Reach...

On Nov 21, 3:08 am, Joe Sneed <jsn... at> 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.edu

  • Prev by Date: Re: ListAnimate and GIF format saving
  • Next by Date: Re: Plotting Points with Labels
  • Previous by thread: Re: StringInput Question
  • Next by thread: simple Button code hangs dynamic evaluation: why?