progress bar code
Code: Select all
[h:abort(1)]
[h, if(json.type(macro.args) != "UNKNOWN"), CODE:{
[totalIteration = arg(0)]
[currentIteration = arg(1)]
};{
[totalIteration = 2000]
[currentIteration = 1]
}]
[frame("Progress Bar", "width=410; height=10; temporary=0"): {
<table width=305px bgcolor='red'><tr><td>
[h:prog.percentage = floor(100*currentIteration/totalIteration)]
<table width=[r:3*prog.percentage]px bgcolor = 'green' color='white'><tr><td>[r:prog.percentage]% [r:if(band(currentIteration,1), "0", "o")]</td></tr>
</td></tr></table>
}]
[h:'<!----------------------------- here you can do your calculations -->']
[h: setLibProperty("iteration"+currentIteration, currentIteration, "lib:Test")]
[h:'<!----------------------------- /here you can do your calculations -->']
[h:currentIteration = currentIteration + 1]
[h: link = macroLinkText("progress bar@Lib:Test", "self", json.append("",totalIteration, currentIteration))]
[h, if(currentIteration < totalIteration):execLink(link,1); closeFrame("Progress Bar")]
Code: Select all
[for (i, currentIteration*10, currentIteration*10 +10), CODE:{ <!--do your stuff here-->}]]
And there are a couple of big advantages:
1. you can see the progress (duh), especially for long interations this can be very usefull as i sometimes have iterations that can take upto 15 minutes and you have no clue whether its still running or not...
2. loops > 1000 yes, cause its deferred no more 'max loop limit' issues
3. you can still interact with MT, albeit very slow, because its a deferred loop you can still interact.
4. you can break it off at any moment: because of 3. you can just edit the running macro and set the 'abort(1)' to 'abort(0)' and the loop immediately stops.
edit: if case your curious on a win7, Quad CPU @ 2.66Hz (64 bits) I run the progress bar without anything 'here you can do your calculations' (so a base benchmark). I've done 100, 1000 and 10000 loops and it very consistently takes 14 ms per cycle. So in case of 10k loops the progress bar will add an additional 2m20s to the run time... unless I choose to use update the bar every 100 cycles in which case it will add only 1,5 second to the routine!