7

Why does the following work for Module but not DynamicModule?

Module[{test}, 
  test = 0;
  Column[{Button["Calc", 
            test = 0.1; Pause[1.0]; 
            test = 0.25; Pause[1.0]; 
            test = 0.5; Pause[1.0]; 
            test = 0.75; Pause[1.0]; 
            test = 0.9; Pause[1.0]; 
            test = 1.0, Method -> "Queued"], 
  Row[{"Progress: ", ProgressIndicator[Dynamic[test]]}]}]]

enter image description here

DynamicModule[{test}, 
  test = 0;
  Column[{Button["Calc", 
            test = 0.1; Pause[1.0]; 
            test = 0.25; Pause[1.0]; 
            test = 0.5; Pause[1.0]; 
            test = 0.75; Pause[1.0]; 
            test = 0.9; Pause[1.0]; 
            test = 1.0, Method -> "Queued"], 
  Row[{"Progress: ", ProgressIndicator[Dynamic[test]]}]}]]

enter image description here

If I have other reasons to need the module to be a DynamicModule, how can I get this functionality to work?

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
Kevin Ausman
  • 2,267
  • 8
  • 16

1 Answers1

6

Thanks to @chuy, we have a solution:

DynamicModule[{test}, 
  test = 0;
  Column[{Button["Calc", 
            test = 0.1; Pause[1.0]; 
            test = 0.25; Pause[1.0]; 
            test = 0.5; Pause[1.0]; 
            test = 0.75; Pause[1.0]; 
            test = 0.9; Pause[1.0]; 
            test = 1.0, Method -> "Queued"], 
  Row[{"Progress: ", 
       ProgressIndicator[Dynamic[Refresh[test]]]}]}]]
Kevin Ausman
  • 2,267
  • 8
  • 16