Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text bottom

PROGRES  PowerBASIC  Routine

         

PROGRES routine displays processing progress indicator and is intended for use in the file processing procedures (external executables started from the DOS command prompt) having a relatively short running time (about 1 minute).  For the longer running procedures the PROGRTM routine (with the elapsed/left time display) might be more appropriate.

Debugging program provides an example of the PROGRES routine usage with the three characteristic CALL lines (color-coded):

  • Start of processing — right after opening the file.  Initiates progress indicator display.
  • Progress of processing — right after reading each record of the file being processed (within the cycle of reading and processing file records).  Updates progress indicator display as each file record is being processed.
  • Finish of processing — after encountering the End-Of-File.  Completes progress indicator display.

The program source text below contains some symbols (the most essential of them are highlighted in red) that were changed from those well-suited for DOS into those acceptable for Windows.  While you can use the PROGRES.BAS text that is fully functional, you'll be better off saving the PROGRES.DOS text instead.  Rename it into PROGRES.BAS and compile to get a module with good DOS defaults.

If you'll choose to set your own progress symbols, any decent DOS text editor (including PowerBASIC IDE) would provide you with the table of all DOS symbols to choose from.  Decimal color codes (PROGRES.BAS needs them in hex) can be found in the COLOR command description of PowerBASIC IDE (in fact any BASIC has this description).  You can use the SETCOLOR batch script demo to see the appearance of bright colors on the Black background.

Note:

It is essential that the calling procedure won't display any information on the screen while the PROGRES routine is active — otherwise the screen would be messed up.




 PROGRES  Source  Program                     Debugging program                 Debugging logout

      ' PROGRES(2.1)  Display File Proc Progress Indicator   06/27/1994-03/26/2003
      ' --------------------------------------------------------------------------
      ' Copyright (C) 1994-2003 by Vladimir Veytsel                  www.davar.net

      ' Type ---------------------------------------------------------------------

      '    Routine

      ' Declaration --------------------------------------------------------------

      '    DECLARE SUB PROGRES(File%,Nam$,Title$,Record$,Mode$,Appear$)

      ' Parameters ---------------------------------------------------------------

      '    File%    - File number (as it was opened in calling program)
      '    Name$    - Program name and version (E.g.:  "CONVERT(0.0)")
      '    Title$   - Process title string (truncated to 64 chars if longer)
      '    Record$  - Current input record
      '    Mode$    - Progress indicator display mode:
      '               S  - Start
      '               P  - Progress
      '               F  - Finish (any value different from "S" or "P" is equivalent to "F")
      '    Appear$  - Appearance control string (fixed structure 6-character):
      '               +------- Incomplete symbol          (Default:  ">")
      '               |+------ Complete   symbol          (Default:  "=")
      '               ||+----- Incomplete color attribute (Default:  "E"  - Yellow)
      '               |||+---- Complete   color attribute (Default:  "B"  - Bright Cayan)
      '               ||||+--- Running    color attribute (Default:  "A"  - Bright Green)
      '               |||||+-- Background color attribute (Default:  "0"  - Black)
      '               ||||||
      '               123456
      '               >=EBA0 - Default appearance control string (padded with blanks)
      '                        Individual blanks default to corresponding symbols
      '                 Note:   This parameter is processed only in "Start" mode
      '                        (in "Progress" and "Finish" mode it is ignored)

      ' Notes --------------------------------------------------------------------

      '  - Routine is intended for use in file processing/conversion procedures
      '    running from DOS prompt and showing processing progress on DOS screen.
      '  - Use it with short running (about 1 minute) procedures.
      '  - For long procedures see routine PROGRTM (with elapsed/left time display).
      '  - Rotating indicator wheel is synchronized with completeness % display.

      ' Examples -----------------------------------------------------------------

      '    Start:  CALL PROGRES(1,"CONVERT(0.0)","File...","","S",">=EBA0")  - After OPEN

      '    CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT
      '         0% [-]   >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

      '    Progress:  CALL PROGRES(1,"","",Input.Record$,"P","")  - After every LINE INPUT

      '    CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT
      '        50% [|]   =====================>>>>>>>>>>>>>>>>>>>>>

      '    Finish:  CALL PROGRES(1,"","","","F","")  - After encountering EOF

      '    CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT
      '       100% [*]   ==========================================

      ' Start Routine ------------------------------------------------------------

           DEFINT A-Z     ' All defaulted variables are integer
           OPTION BASE 1  ' Default array indexation starts from "1"

           SUB PROGRES(File%,Nam$,Title$,Record$,Mode$,Appear$) STATIC PUBLIC

           DIM Wheel$(4)

      ' Initialize Routine Constants (Start) -------------------------------------

           SELECT CASE (UCASE$(Mode$))
                  CASE ("S")
                       Wheel$(1)="-"
                       Wheel$(2)="\"
                       Wheel$(3)="|"
                       Wheel$(4)="/"
                       IF (LEN(Appear$)=0) THEN
                          App$=">=EBA0"  '
                       ELSE
                          App$=Appear$+"      "
                       END IF
                       Incompl.Symb$    =MID$(App$,1,1)
                       Complete.Symb$   =MID$(App$,2,1)
                       Incompl.Color$   =MID$(App$,3,1)
                       Complete.Color$  =MID$(App$,4,1)
                       Running.Color$   =MID$(App$,5,1)
                       Background.Color$=MID$(App$,6,1)
                       IF (Incompl.Symb$    =" ") THEN Incompl.Symb$    =">"
                       IF (Complete.Symb$   =" ") THEN Complete.Symb$   ="="
                       IF (Incompl.Color$   =" ") THEN Incompl.Color$   ="E"
                       IF (Complete.Color$  =" ") THEN Complete.Color$  ="B"
                       IF (Running.Color$   =" ") THEN Running.Color$   ="A"
                       IF (Background.Color$=" ") THEN Background.Color$="0"
                       Incompl.Color   =VAL("&H"+Incompl.Color$)
                       Complete.Color  =VAL("&H"+Complete.Color$)
                       Running.Color   =VAL("&H"+Running.Color$)
                       Background.Color=VAL("&H"+Background.Color$)

      ' Display Initial Processing Progress Message ------------------------------

           File.Size!=LOF(File%)   ' Get input file size
           IF (LEN(Title$)>57) THEN Title$=LEFT$(Title$,57)
           Title.Len=LEN(Title$)
           Percent.Pos=LEN(Nam$)-8
           Time.Pos=LEN(Nam$)+LEN(Title$)+5
           Share!=File.Size!/Title.Len
           IF (Share!=0) THEN Share!=1
           Limit!=Share!
           COLOR Complete.Color,Background.Color
           PRINT Nam$;"  ";Title$
           PRINT TAB(Percent.Pos);"  0% [";Wheel$(1);"]   ";
           COLOR Incompl.Color,Background.Color
           PRINT STRING$(Title.Len,Incompl.Symb$);
           Length.Ratio!=Title.Len/File.Size!
           Curs.Line=CSRLIN

      ' Redisplay Processing Progress Message ------------------------------------

           CASE ("P")
                Curr.Size!=Curr.Size!+LEN(Record$)+2
                Percent.Compl=Curr.Size!/File.Size!*100
                LOCATE ,Percent.Pos
                COLOR Running.Color,Background.Color
                PRINT USING "###";Percent.Compl;
                PRINT "% [";Wheel$((Percent.Compl MOD 4)+1);"]   ";
                IF (Curr.Size!>Limit!) THEN
                   COLOR Complete.Color,Background.Color
                   PRINT STRING$(Curr.Size!*Length.Ratio!,Complete.Symb$);
                   Counter=Counter+1
                   Limit!=Counter*Share!
                END IF

      ' Redisplay Process Finish Message -----------------------------------------

           CASE ELSE
                COLOR Complete.Color,Background.Color
                LOCATE Curs.Line,Percent.Pos
                PRINT "100% [*]   ";STRING$(Title.Len,Complete.Symb$)

           END SELECT

      ' Finish Routine -----------------------------------------------------------

           END SUB
  
         

 PROGRES  Debugging  Program                     Source program               Debugging logout

      ' PROGRES(2.1)  Display File Proc Progress Indicator   06/27/1994-05/29/1997
      ' --------------------------------------------------------------------------

        $INCLUDE "PROGRES"

        DECLARE SUB PROGRES(File%,Nam$,Title$,Record$,Mode$,Appear$)

        Pause!=0.1
        Appear$=""
      ' Appear$="-*"

        CLS
        PRINT "PROGRES(2.1)  Display File Processing Progress Indicator  ";DATE$;
        PRINT "  ";LEFT$(TIME$,5)
        PRINT STRING$(75,"-")
        PRINT

        OPEN "C:\PBASIC\PROGRES.BAS" FOR INPUT AS #1
        CALL PROGRES(1,"CONVERT(0.0)","File SOURCE.TXT is converted to TARGET.TXT","","S",Appear$)

        WHILE (NOT(EOF(1)))
              LINE INPUT #1,Input.Record$
              CALL PROGRES(1,"","",Input.Record$,"P","")
              DELAY Pause!
        WEND

        CALL PROGRES(1,"","","","F","")

        COLOR 7,0  ' Gray
        PRINT
        PRINT "Execution completed - hit [Enter] to continue..."
  
         

 PROGRES  Debugging  Logout                          Source program                     Debugging program

         

   PROGRES(2.0)  Display File Processing Progress Indicator  05-15-2003  07:57
   ---------------------------------------------------------------------------

   CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT
       24% [-]   ==========>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	
      
         

   PROGRES(2.0)  Display File Processing Progress Indicator  05-15-2003  07:58
   ---------------------------------------------------------------------------

   CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT
       74% [|]   ===============================>>>>>>>>>>>
	
      
         

   PROGRES(2.0)  Display File Processing Progress Indicator  05-15-2003  07:59
   ---------------------------------------------------------------------------

   CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT
      100% [*]   ==========================================

   Execution completed - hit [Enter] to continue...
	
      

         

View [and save] PROGRES.BAS text       View [and save] ZPROGRES.BAS text
View [and save] PROGRES.DOS text – rename into *.BAS and compile
(Use [Back] button or [Alt]+[CL] to return here from the viewed text)
Copyright © 1994–2003 by
Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top