5
$\begingroup$

I want to show a progress indicator while statements in a Module are processed.

Outside a Module this ca be done like this:

messages = {};    
Column[{ Dynamic[zeilenZ]
,  Pane[            
     ProgressIndicator[               
      Dynamic[zeilenZ] 
     , {0, Dynamic[length]}
    ]
   ]   (* Pane *)
  , Dynamic[TextGrid[messages]]
  }
]                 (* a semicolon after the bracket would suppress the ProgressIndicator! *) 
zeilenZ = 0;      (* many computations following *)

However, if I put this sequence of statements into a Module expression, I get an error message Set::write: Tag Times in Null ... is Protected.. If I put a semicolon after the closing bracket of Column, the next line would no longer be understood as a multiplication of Column[....] and what follows it, in my case zeilenZ. But the ProgressIndicator would be suppressed too!

The same would happen, if I would plot something instead of Column.

Of course, I could assign the whole Column statement (or Plot statement) to a variable, but how could I show it on the screen?

The only way out I have conceived so far is to assign the result of the Column statement to a variable col (which initially is assigned the empty list {}) and display that with Dynamic[col] before using the module. It looks like col having to be a global variable for that purpose and my ProgressIndiator appears where the Dynamic[col] is output.

Are there better ways to achieve my objective?

$\endgroup$

1 Answer 1

5
$\begingroup$

Try this:

Monitor[Module[{s}, 
  s = NDSolve[{y'[t] == y[t] Cos[t + y[t]], y[0] == 1}, 
    y, {t, 0, 100000}, StepMonitor :> (time = t)]], 
 ProgressIndicator[time/100000]]

enter image description here

or this:

tEnd = 100000;
ProgressIndicator[Dynamic[currentTime], {0, tEnd}]

currentTime = 0;
Module[{s}, 
 s = NDSolve[{y'[t] == y[t] Cos[t + y[t]], y[0] == 1}, 
   y, {t, 0, tEnd}, EvaluationMonitor :> (currentTime = t;)]]

Have fun!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.