In article <[EMAIL PROTECTED]>, Malcolm Cadman
<[EMAIL PROTECTED]> writes

>Has anyone written a progress bar in SuperBASIC ?
>
>To inform the user of the progress made during a longish operation like
>processing a file.
>
>A graphical presentation would also be useful.
>
>0% ****...............100%
>
>( Crude ASCII illustration above ).

Thanks for all the replies to the above query.  It has helped a lot.

The listing below is based on Dilwyns help, and works as a 'stand alone'
program for illustration purposes.

Bar1 >

15000 REMark File Processed bar - Test code
15010 OPEN#5,con_512x12a0x14_30
15020 WINDOW#5,458,12,22,14
15030 CLS
15040 filelength% = 10000 : REMark A nominal file length being processed
15050 linenumber% = 1 : REMark Start count value
15060 increment% = filelength% - 100 : REMark A nominal value for one
line of file ...
15070 bar_width% = filelength% / 100 : REMark A nominal easy 100 for
total
15080 bar_height% = 10
15090 background_col% = 2 : REMark total filelength shown in this colour
15100 progress_col% = 4 : REMark Progress shown in this colour
15110 REMark Show full bar for original file length
15120 PRINT#5,'0% ';
15130 BLOCK #5,bar_width%,bar_height%,12,0,background_col%
15140 CURSOR#5,12+bar_width%,0 : PRINT#5,' 100%'
15150 :
15160 REPeat progress
15170   REMark A nominal value of 1/100ths for one line ...
15180   increment% = (filelength% - linenumber%*100) / 100
15190   progress_bar increment%
15200   linenumber% = linenumber% + 1
15210   REMark AT#0,10,0: PRINT'Linenumber = ';linenumber%
15220   REMark AT#0,12,0: PRINT'Increase = ';increase%
15230   IF linenumber% > 100 : EXIT progress
15240 END REPeat
15250 :
15260 STOP
15270 :
15280 DEFine PROCedure progress_bar(increment%)
15290 REMark Progress bar code from idea thanks to Dilwyn Jones February
2003
15300 REMark Graphical progress bar
15310 LOCal progress_pix%, pix_per_line%
15320 REMark Number of pixels for one line
15330 pix_per_line% = bar_width% - increment%
15340 REMark How many pixels to represent progress through file ?
15350 progress_pix% = pix_per_line%*increase%
15360 IF progress_pix% > bar_width% THEN progress_pix% = bar_width%
15370 REMark Show progress bar
15380 BLOCK #5,pix_per_line%,bar_height%,12,0,progress_col%
15390 END DEFine
15400 :
15410 DEFine PROCedure s
15420 SAVE ram1_bar
15430 SAVE win1_basicprogs_bar
15440 END DEFine

The second listing is how I am applying a progress bar in my program.
This only works when reading in an actual file.

Bar2 >

15000 REMark File Processed bar - Test code
15010 DEFine PROCedure progress_bar
15015 REMark Progress bar code from an idea thanks to Dilwyn Jones
February 2003
15020 LOCal background_col%,progress_col%
15030 LOCal bar_width%,bar_height%
15035 LOCal percentage%
15070 bar_width% = 100 : REMark An easy 100 for total
15080 bar_height% = 10
15090 background_col% = 2 : REMark total filelength shown in this colour
15095 progress_col% = 4 : REMark progress made shown in this colour
15100 REMark Show full bar for original file length
15110 PRINT#5,'0%';
15120 BLOCK #5,bar_width%,bar_height%,12,0,background_col%
15130 CURSOR#5,bar_width%,0 : PRINT#5,'100%'
15270 REMark Graphical progress bar
15310 REMark Number of pixels to show for line(s) processed
15315 percentage% = 100*FPOS(#channel_in%)/FLEN(#channel_in%)
15360 REMark Show progress bar
15370 BLOCK #5,percentage%,bar_height%,10,0,progress_col%
15375 REMark Also show percentage completed
15377 AT#5,0,72: PRINT#5,percentage%;'%'
15380 END DEFine
15390 :

I hope that these examples are also helpful to others.

-- 
Malcolm Cadman

Reply via email to