Gas Bar

Published ByDateVersionKnowledge LevelKeywords
Sprezzatura Ltd01 JUN 19891.13+EXPERTGAS.BAR, @REC.COUNT, STATUS.CONSTANTS, STATUP, @RN.COUNTER

They say that imitation is the sincerest form of flattery so the chaps at RevTech ought to be pleased by the following program. One of the features that I found the most visually appealing in Release 1.1 was what was euphemistically described as the "Gasometer" on the status line when SELECTS or SORTS were in progress. (Obviously the Americans have never lived next door to a British Gasometer). Naturally I wanted to copy this in my own programs but got a little tired of always rewriting the same code, so on the next page please find a listing for a routine that I've called "GAS.BAR" (please, call it what you will). This emulates the functionality of the AREV gasometer but can be used from ANY program which sets @REC.COUNT and then loops through processing each record in the select list. It would be a simple mod to make the program accept a passed record count if @REC.COUNT was not set but I'm trying to keep all code listings to a minimum so I'll leave that to you.

To use, simply enter the program, compile and catalogue it. Then at the top of your program declare subroutine GAS.BAR and within your READNEXT loop, insert the statement GAS.BAR(). E.G.

          EQU  TRUE$          TO 1
          EQU  FALSE$    TO 0
          EOF = FALSE$
          DECLARE SUBROUTINE GAS.BAR
          PERFORM "SELECT MYFILE"
          LOOP
              READNEXT ID ELSE EOF = TRUE$
          UNTIL EOF DO
              GOSUB RECORD.PROCESSING
              GAS.BAR()
          REPEAT

And so, to the code dissection -

NB This routine adds about 3 seconds to the processing of 1000 records, or about .003 seconds per record - a speed sacrifice well worth it for "user friendliness".

0001 SUBROUTINE GAS.BAR
0002 *
0003 *    Author    AMcA
0004 *    Purpose   To display a "Gas Bar" on status line when
0005 *    processing records to indicate progress
0006 *    like in the AREV "Select" process.
0007 *    Copyright Sprezzatura Ltd 1989
0008 *    Permission is granted for REVMEDIA
0009 *    subscribers to use this program for
0010 *    any purpose.  (At your own risk!)
0011
0012 $INSERT BP,STATUS.CONSTANTS
0013 COMMON/%%GAS.BAR%%/LAST.PERCENT,SAVED.STATUS
0014 EQU VERT$ TO CHAR(170)
0015 EQU BLOCK$     TO CHAR(219)
0016
0017      IF @REC.COUNT THEN
0018           IF LAST.PERCENT = "" THEN
0019                *
0020                * 1st time in, save status line and set LAST.PERCENT
0021                *
0022                STATUP(PUSH$,"",SAVED.STATUS)
0023                LAST.PERCENT = 0
0024                @RN.COUNTER = 1
0025                GOSUB DISPLAY.BAR
0026           END ELSE
0027                *
0028                * Must be in loop so determine display action
0029                *
0030                IF @RN.COUNTER = @REC.COUNT THEN
0031                     *
0032                     *Loop done, remove display and reset stat line
0033                     *
0034                     STATUP(SINGLE$,3,SPACE(62))
0035                     STATUP(POP$,"",SAVED.STATUS)
0036                     LAST.PERCENT = "" ; SAVED.STATUS = ""
0037                END ELSE
0038                     GOSUB DISPLAY.BAR
0039                END
0040           END
0041      END ELSE
0042           LAST.PERCENT = "";SAVED.STATUS =""
0043      END
0044 RETURN
0045
0046 DISPLAY.BAR:
0047      RC= @REC.COUNT ; * done to fit next line on single line
0048      PERCENT = INT((@RN.COUNTER)/RC) * 100)
0049      IF PERCENT # LAST.PERCENT THEN
0050           GRAPH :="Done" : VERT$ : PERCENT "R(0)#3" : "%": VERT$
0051           GRAPH := STR(BLOCK@,INT(PERCENT/2))
0052           STATUP(SINGLE$,3,GRAPH)
0053           LAST.PERCENT = PERCENT
0054      END
0055 RETURN

(Volume 1, Issue 2, Pages 10,11)