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

PROGRTM  PowerBASIC  Routine

         

PROGRTM 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 long running time (several minutes).  For the shorter running procedures the PROGRES routine (without the elapsed/left time display) might be more appropriate.

Debugging program provides an example of the PROGRTM 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.

If you'll choose to set your own progress symbols, any decent text editor (including PowerBASIC IDE) would provide you with the table of all symbols to choose from.  Color codes (PROGRTM.BAS needs them in hex) can be found in the COLOR command description of PowerBASIC IDE.

Note:

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




 PROGRTM  Source  Program                       Debugging program                   Debugging logout

      ' PROGRTM(1.1)  Display File Process Progr Ind with Times  06/27/1994-02/14/2010
      ' ------------------------------------------------------------------------------
      ' Copyright (C) 1994-2010 by Vladimir Veytsel                      www.davar.net

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

      '    Routine

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

      '    File%    - File number (as it was opened in the calling program)
      '    Nam$     - 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 command prompt and showing processing progress on a screen.
      '  - Routine properly handles running time of 99 minutes MAXimum.
      '  - Use it with long running (over 1 minute) procedures.
      '  - For short procedures see routine PROGRES (without elapsed/left time display).
      '  - Rotating indicator wheel is synchronized with completeness % display.
      '  - Processing elapsed time & estimate of processing left time is shown as MM:SS.
      '  - Evaluation and display of left time starts after 5% processing completeness.

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

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

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

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

      '    CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT   Elap   Left
      '        50% [|]   =====================>>>>>>>>>>>>>>>>>>>>>   6:30   6:20

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

      '    CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT   Elap   Left
      '       100% [*]   ==========================================  12:50   0:00

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

           DEFINT A-Z     ' All defaulted variables are integer

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

           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 ----------------------------------

           Start_Time!=TIMER
           File_Size!=LOF(File%)  ' Get input file size
           CONSOLE GET SCREEN TO Rows&,Columns&
           Max_Title_Len=Columns&-LEN(Nam$)-16
           IF (LEN(Title$)>Max_Title_Len) THEN Title$=LEFT$(Title$,Max_Title_Len)
           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$;"   Elap   ";
           COLOR Running_Color,Background_Color
           PRINT "Left"
           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
                Elapsed_Time=TIMER-Start_Time!
                IF (Elapsed_Time>Prev_Time) THEN
                   Prev_Time=Elapsed_Time
                   COLOR Running_Color,Background_Color
                   LOCATE Curs_Line,Time_Pos
                   Dspl_Time=Elapsed_Time
                   GOSUB Display_Time
                   IF (Percent_Compl>4) THEN
                      Left_Time=Elapsed_Time*(File_Size!-Curr_Size!)/Curr_Size!
                      LOCATE Curs_Line,Time_Pos+7
                      Dspl_Time=Left_Time
                      GOSUB Display_Time
                   END IF
                END IF
                LOCATE Curs_Line,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,Time_Pos
                Dspl_Time=Elapsed_Time
                GOSUB Display_Time
                LOCATE Curs_Line,Percent_Pos
                PRINT "100% [*]   ";STRING$(Title_Len,Complete_Symb$)

           END SELECT

           GOTO Finish_Routine

      Display_Time:  ' Routine ------------------------------------------------------

           Dspl_Mins=INT(Dspl_Time/60)
      '    Dspl_Mins=Dspl_Mins+10  ' Uncomment for testing of 10+ minute span formatting
           Dspl_Secs=INT(Dspl_Time MOD 60)
           PRINT USING$("##",Dspl_Mins);
           PRINT ":";
           IF (Dspl_Secs<10) THEN
              PRINT "0";
              PRINT USING$("#",Dspl_Secs);
           ELSE
              PRINT USING$("##",Dspl_Secs);
           END IF

           RETURN  ' From Display_Time routine

      Finish_Routine: ' --------------------------------------------------------------

           COLOR 7,0  ' Restore Gray on Black

           END SUB
  
         

 PROGRTM  Debugging  Program                   Source program               Debugging logout

      ' PROGRTM(1.1)  Display File Process Progr Ind with Times  06/27/1994-02/14/2010
      ' ------------------------------------------------------------------------------

        #INCLUDE "PROGRTM"

        FUNCTION PBMAIN

        Pause!=100

        PRINT "PROGRTM(1.1)  Display File Process Progress Indicator with Times  ";DATE$;
        PRINT "  ";LEFT$(TIME$,5)
        PRINT STRING$(83,"-")
        PRINT

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

        WHILE (NOT(EOF(1)))
              LINE INPUT #1,Input_Record$
             CALL PROGRTM(1,"","",Input_Record$,"P","")
              SLEEP Pause!
        WEND

        CALL PROGRTM(1,"","","","F","")

        END FUNCTION
  
         

 PROGRTM  Debugging  Logout                       Source program                   Debugging program


   PROGRTM(1.1)  Display File Process Progress Indicator with Times  09-18-2016  23:03
   -----------------------------------------------------------------------------------

   CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT   Elap   Left
       24% [-]   =========>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>   0:04   0:14
        


   PROGRTM(1.1)  Display File Process Progress Indicator with Times  09-18-2016  23:03
   -----------------------------------------------------------------------------------

   CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT   Elap   Left
       75% [/]   ===============================>>>>>>>>>>>   0:14   0:05
        


   PROGRTM(1.1)  Display File Process Progress Indicator with Times  09-18-2016  23:03
   -----------------------------------------------------------------------------------

   CONVERT(0.0)  File SOURCE.TXT is converted to TARGET.TXT   Elap   Left
      100% [*]   ==========================================   0:19   0:00
        

         

View [and save] PROGRTM.BAS text       View [and save] ZPROGRTM.BAS text
(Use [Back] button or [Alt]+[CL] to return here from the viewed text)
Copyright © 19942010 by
Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top