Marked as: Easy
Hello,
This example show you how one can create a progress bar that travels back and forth to show that the script is busy processing something. Quite neat when one can't calculate the time left nor have any other measurement on how far away the finish may be.
Description:
The first call to the function configure it and draw the initial characters, consecutive calls move the characters one step forward for each call. 3 global variables ( count_ width_ pos_y_ ) store information between each call. The usage of the character "_" in the end was chosen to not interfere with normal naming of variables.
In this example you'll learn how calculations with % work (divide and keeps the whole number part ), as well as // (keep the remainder).
NOTE: Changed % 2 to // 2... Now it should behave better. 2008-04-07 //Jan-Erik
/* Fading away */
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs
call SysCls
call rxFade 2, 23
do i = 1 to 100
call SysSleep 1
call rxFade
end
Return 0
rxFade: procedure expose count_ width_ pos_y_
if datatype( count_, "W" ) = 0 then count_ = 1
if datatype( width_, "W" ) = 0 then
if datatype( ARG(2), "W" ) = 0 then width_ = ARG(2)
else width_ = 20
if datatype( pos_y_, "W" ) = 0 then
if datatype( ARG(1), "W" ) = 0 then pos_y_ = 0
else pos_y_ = ARG(1)
do i = min( 4, count_ ) to 0 by -1
pos_x = ( count_ - i ) // width_
if ( count_ - i ) % width_ // 2 = 1 then
pos_x = width_ - pos_x
parse value SysCurPos( pos_y_, pos_x ) with prev_row prev_col
select
when i = 4 then
say ' '
when i = 3 then
say '░'
when i = 2 then
say '▒'
when i = 1 then
say '▓'
otherwise
say '█'
end
call SysCurPos prev_row, prev_col
end
count_ = count_ + 1
Return 0