Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Dynamic not displaying the current value

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110040] Dynamic not displaying the current value
  • From: Fred Simons <f.h.simons at tue.nl>
  • Date: Sun, 30 May 2010 23:44:20 -0400 (EDT)

Rarely, Dynamic does not display the current value. This is the simplest 
example I know:

n=0;
Dynamic[n]
Do[Pause[0.2],{n,1,5}]

Recently, I found another example. It has to do a lot with DynamicModule 
and the option InheritScope, and I highly appreciate the contributions 
of John Fultz in this group. Without his explanations and references I 
think I would have been unable to construct this almost working example.

CreateDocument[
DynamicModule[{a=0.5}, Button["Start", 
CreateDocument[{DynamicModule[{},Column[{Slider[Dynamic[a]], 
Dynamic[a]}], InheritScope->True],
DynamicModule[{b},Button["Secondary 
screen",b=a;CreateDocument[{Slider[Dynamic[b]], Dynamic[b]}, 
WindowTitle->"secondary screen", 
NotebookEventActions->{"WindowClose":>(a=b)}]], InheritScope->True],
DynamicModule[{},Button["Print a",Print[a]], InheritScope->True]}, 
Saveable->False, WindowTitle->"main screen", WindowSize->Scaled[1.0]]] ],
WindowTitle->"start screen"];

In this example, there is a main screen, in which I can manipulate the 
variable a. There is a secondary screen, in which I also want to 
manipulate the variable a, but in such a way that there is no effect in 
the main screen. This is done by using a local variable b, initially set 
to a, that can be manipulated in the secondary screen, and on closing 
the secondary screen, the variable a is set to b.

This almost works. Evaluate the command, press Start, use the slider, 
press Secondary screen, use the slider for manipulating b and close the 
secondary screen. Everything works fine, apart from the fact that the 
slider and Dynamic[a] in the main screen now do not display the latest 
value for b. Nevertheless, thecurrent value of a IS the latest value of 
b, as can be seen by pressing 'Print a'. So it is only the display in 
the main screen that is incorrect.

There is a trivial workaround for these problems: simply add the option 
UpdateInterval->0.5 to the Dynamic commands in the main screen. But that 
is very unelegant and my feeling is that, in particular in the second 
example, there must be a better way.

Any comment is welcome.

Fred Simons
Eindhoven University of Technology


  • Prev by Date: Re: Basic normal and t table questions
  • Previous by thread: Re: Basic normal and t table questions