cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[HOW TO] Setup a Progress Bar in macro execution

cpucci
MEGA
MEGA

This article teach how to implement a progress bar (called also gauge) to show the execution progression of a script. The progress bar can be put inside an existing window or can create a new window if required. It is useful to give a visual feedback to the user while MEGA is executing a time consuming script.

 

When executing a time consuming script you can setup a Progress Bar to let the user know that something is happening, and also show an estimation of the progress if you know how much steps you will need to complete.

 

Mega has the MegaProgressControl object to implement progress bars.


If you are inside a wizard then the progress bar will be put in the bottom left corner of the wizard.
If you are not in a wizard then a new popup window will appears, just with the progress bar and a status line.

 

To create this use the following code (root is a MegaRoot😞

 

JAVA
MegaProgressControl pBar = new MegaProgressControl(root);
pBar.create();
pBar.text("I'm a progress bar");
pBar.setRange(0, 1000);
for(int i=0; i<1000; i++) {
    pBar.status("We are at " + i);
    pBar.setGauge(i);
}
pBar.destroy();

 

VB
set pBar = root.ContextObject("#Window")
pBar.create
pBar.text = "I'm a progress bar"
pBar.setRange 1, 1000
for i=1 to 1000
    pBar.status = "We are at " & i
    pBar.setGauge i
next
pBar.destroy


If you want to know if the user clicked on the "Abort" button then check the value pBar.isAborted() (method in Java, value in VB),if the result id true then the user clicked on the abourt button.

 

The list of available methods is (Java version, but VB is pretty the same, just use all methods as properties in VB):

  • MegaProgressControl.text(String title) Robot surprised Add a title to the progress bar
  • MegaProgressControl.status(String status) Robot wink Add a status to the progress bar, useful to show what the script is doing
  • MegaProgressControl.create() Robot Happy The progress bar is created, in this call if a container window exists (like a Wizard) then the progress bar is attached to it, if not a new popup window is created
  • MegaProgressControl.destroy() Robot Mad Destruction of the object. Is mandatory to call it or you will get an error when your script will terminate
  • MegaProgressControl.setRange(int min, int max ) Robot Embarassed Range of values for the progress bar, the minimum min is 0, the maximum max is 32768
  • MegaProgressControl.setGauge(int val) Robot wink Set the progress bar at the specified value
  • MegaProgressControl.incrementRange(int val) Robot Frustrated Increment the progress bar of the passed value
  • MegaProgressControl.isAborted() Robot surprised Returns a boolean to understand if the user clicked on the Abort button.
  • MegaProgressControl.abort() Robot SadHas to be called to activate the Abort button

Let the user know what's happening!

Claudio Pucci
0 Replies