PillarSoft

http://www.pillarsoft.net/os-2-software/rexx/another-progress-bar-for-vispro-rexx.shtml

Another Progress Bar for Vispro Rexx

Contributed by: David Muir

I was looking for a progress bar that looked a little closer to what I'm familiar with than the other example on this site. So here is my take on the matter. Using 2 "Entry Field" objects we can approximate the look and behaviour of a progress bar. This approximates the look of the familiar progress bar by providing a white bar with a filled in portion (and optionally a text percentage displayed in the blue portion). Forgive me if my coding is less than appealing. I am VERY new to Vispro REXX.


 

 

/* Progress Bar requires using 2 "ENTRY FIELD" tools.

-- Entry field 1 settings --

      Symbol -
            PBBACK Position -
            must be placed "exactly" where you want your progress bar to show in your project. Size -
            Size precisely to match your desired size for your progress bar. Settings -
            Read Only
            Margin BackGround colour -
            WHITE -The desired background colour for your progress bar (Normally this is white)


-- Entry field 2 settings --

      Symbol -
            PBFRONT Position -
            Can be virtually anywhere (on the same form as field 1). Generally place it on or under field 1. Size -
            Size is not important (it is set at run-time) Settings -
            Read Only
            NO Margin Alignment -
            Center (personal preference may vary) BackGround colour -
            BLUE - The desired FOREGROUND colour for your progress bar (Normally this is BLUE) ForeGround colour -
            WHITE - The desired colour of TEXT that may appear on the blue portion of the progress bar (Normally this is white) Font -
            Size to suit based on the height of your progress bar. Note that this is only significant if you wish to display the percentage complete as text in the progress bar.


-- preparation --

      - Place the following code block in any event of the form that contains your progress bar. Code between if 0 then do and end will not be executed unless specifically called by label.
      - run "rc = SetUpProgressBar()" one time prior to using "ProgressBar" to set the variables that are needed for proper operation.


-- Usage --

      Run rc = SetUpProgressBar() once to initialize the variable.
      Run ProgressBar(#) where # = the percent of progress for the bar to display.
      repeat calling Progressbar(#) as needed to update the progress bar.


-- Significant notes --

      Background colours of PBFRONT and PBBACK must be different
      The height of PBBACK (the white background bar) must be at LEAST 5 pixels in order for the progress to be seen.
      This progress bar is really only a graphical representation of a percentage. To give the illusion of a progress bar, update it as frequently as necessary with new (usually higher) values between 1 and 100.

--Test Code--
To test the progress bar you could insert this code into an event and then activate the event.
----------

      rc = SetUpProgressBar()
      testvalue = 3000 /* a seed value the higher the number the slower the progress */
      DO index = 1 to testvalue*100 by 1
            /* this only updates the progress bar if the value is a whole number */
            if index//testvalue = 0 then rc=progressbar(index/testvalue)
            END

----------
*/

if 0 then do

SetUpProgressBar:
   xy=VpItem(window,PBBACK,'ITEMPOS')       /* Get the position of the background bar */
   PARSE VAR xy progressx progressy
   xysize=VpItem(window,PBBACK,'ITEMSIZE')  /* Get the size of the background bar */
   PARSE VAR xysize progressxsize progressysize
   /* put the foreground bar in the same place as the background bar */
   /* size the foreground bar to 0,0 to prevent it from showing */
   CALL VpItem window,PBFRONT,'SETITEMPOS',progressx,progressy,0,0
   return('')


ProgressBar:
   /* you must run SetUpProgressBar ONCE before using this Procedure */
   /* call as progressbar(#) where # is the percent to show */
   parse arg percenttoshow
   CALL VpItem window,PBFRONT,'SETITEMPOS',progressx+2,progressy+2, (progressxsize-4) * percenttoshow / 100 ,progressysize-4
   CALL VpSetItemValue window,PBFRONT,percenttoshow'%' /* comment out this line to stop the percent from showing in text on the bar */
   return('')


end