The idea is to change progressBar2 to make it usable inside Module without necessity to call Dynamic and Print.
I've seen this similar post
How to create a progress bar?
, but didn't get how to upgrade my code.

1 Answer
1

Your definition is progressBar2 is essentially correct, but it is evaluating its arguments. This causes the symbol i to disappear from your example as evaluation replaces i with its value. The simplest fix is to SetAttributes[progressBar, HoldFirst].

However, we see that almost all Mathematica controls require us to specify explicit Dynamic wrappers for dynamic variables. The purpose of this convention is to help people reading the code spot parameters that are subject to special dynamic processing. We could follow that convention by making some minor changes to the definition of the progress bar function:

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.