'=========================================================================== ' Subject: PERCENTAGE BAR ROUTINE Date: 03-08-96 (00:00) ' Author: James Goldbloom Code: PB ' Origin: FidoNet QUIK_BAS Echo Packet: PB.ABC '=========================================================================== 'I wrote this originally for Power Basic, but I've decided to link up to this 'echo and share some PB code which could easily be adapted to QB, and 'is useful for some... 'I decided to share one of my routines with you nifty people, so I formatted 'it for this echo area and included help and tips, etc. It's a complete 'program which demonstrates a fully graphical percentbar for use in any 'of your programs which do lots of loops and activities requiring a 'percentage of completion, etc. It works forwards or backwards, can 'be told to use numerical values in the display or not, and can also 'be used to display instant percentbars without needing to loop at all! 'This routine works decently, and can be called within your loops to 'show progress bars during copies, disk reads, alphabetizing, etc., 'in a totally GRAPHICAL manner at any nearly any position on the screen 'with the width and numerical display programmer defined! 'It's really neat, and I spent only marginal time creating it. It 'also restores the previous color/cursor position from where the routine 'was called, so NO need to worry with that stuff. It's something I 'am most proud of, and also - it's fast. Thanks to Brian who earlier 'posted tips on screen color restore, showing we all share but give 'credit where credit is due. 'You can supply the width,x,y positions and other criteria like a normal 'function, and tie it into loops to display real time percentbars. 'The output will resemble this (for example): 'ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´500/1000ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ '³50% ²²²²²²²²²²²²²²²²²²²²þþþþþþþþþþþþþþþþþþþþ³ 'ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ 'ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ '³50% ²²²²²²²²²²²²²²²²²²²²þþþþþþþþþþþþþþþþþþþþ³ 'ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ 'The first one shows the graphics bar (the progress graphics really 'are spaces, but for purposes of this echo msg, are graphical boxes instead) 'WITH numerical values displayed, the second without. Note that the 'numerical displays automatically format the box, so the output is clean 'and does not include unnecessary spaces and so forth. Cool, huh? ' PERCENTAGE BAR ROUTINE - WORKS FORWARD OR BACKWARDS OR STATIC VALUE! ' by JAMES GOLDBLOOM with color restore method courtesy of Brian McLaughlin ' Public domain code - distribute freely and enjoy (3/8/96 PB 3.x) ' Syntax shown below: ' ' call percentbar (valuebar,lowbar,highbar,ybar,xbar,widthbar,showvalues) ' ' Where: valuebar = current value of operation within the range ' lowbar = lowest possible (or beginning) value of range ' highbar = highest possible (or ending) value of range ' ybar = cursor line to place percentbar (y axis) ' xbar = corsor row to place percentbar (x axis) ' widthbar = width of percentbar dots (in columns) (max 72) ' and suggest values: 12,18,40,50,72 (they work.) ' showvalues = 0|1 (1 to display current/high valuees, 0=off) ' ' All values should be positive, but decimals are allowed. Widthbar ' seems to look the nicest at 72 (which is the limit.) Remember to freeze ' the cursor by suffixing print/screen output statements with semi-colons ' to preserve the colors and x,y positions properly within your loops. ' ' Use this routine for progress display during file/dir. reads or ANY loop ' operations by merely calling it using data from YOUR loops fed into it! ' Shows actual percentage (0-100%) to left of bar, automatically! ' Last color attribute/screen x,y position automatically preserved on exit! ' Work with high to low ranges, or low to high ranges (try it backwards!) ' Loops not required, you can optionally show a bar with "50%" instantly! ' ' See the example below, mess with the ranges... cls color 11,0 print "PERCENT BAR Stupid but Powerful Demonstration...." print print "This is an instant loop, 50%:"; call percentbar (50,1,100,csrlin,pos+2,36,0) locate 7,1 print "Another instant loop (values shown), 75%:"; call percentbar (75,1,100,csrlin,pos+2,20,1) locate 11,1 print "THIS PROGRAM CAN ALSO BE USED WITHIN LOOPS, FOR/NEXT'S, ETC.!" print:print "A good range to test would be 1 to 10000" print "And you can work backwards, too, such as 10000 to 1!":print input "Type in starting number";begin:if begin=0 then end input "Type in ending number";finish:if finish=0 then end direction=1:if begin>finish then direction=-1 for count=begin to finish step direction locate 19,1:color 10:print"Current loop value:"count"..."; call percentbar (count,begin,finish,23,1,72,1) next count print" Finished!" print "Nifty, huh? Examine the code, see how it was done!" end 'BELOW IS THE SUB ROUTINE... '----------------------------------------------------------------------- 'PERCENTBAR Sub-Routine written by James Goldbloom 1:109/611@Fidonet.org '----------------------------------------------------------------------- ' 'Example: percentbar (50,1,100,24,1,72) <-- Display a 50% bar at bottom! ' of screen! ' SUB PERCENTBAR (valuebar,lowbar,highbar,ybar,xbar,widthbar,showvalues) oldy=csrlin:oldx=pos(0):if oldx=1 then oldx=2 else if oldx=80 then oldx=81 if widthbar>72 then widthbar=72 fore%=screen(oldy,oldx-1,1) back%=fore%:fore%=fore% and 15:shift right back%,4 if lowbar>highbar then swap highbar,lowbar percentage=int((valuebar/highbar)*100) locate ybar,xbar:color 9,0 if showvalues=0 then print chr$(218)repeat$(widthbar+5,chr$(196))chr$(191); if showvalues=1 then tempbar$=mid$(str$(valuebar),2)+"/"+mid$(str$(highbar),2) print chr$(218)repeat$(int(widthbar/2)-1,chr$(196))chr$(180);:color 15 print tempbar$;:color 9:print chr$(195); print repeat$(widthbar-((widthbar/2)+len(tempbar$))+4,chr$(196))chr$(191); end if locate ybar+1,xbar:color 9: print chr$(179);:color 14 print mid$(str$(percentage),2)"%"space$(5-len(str$(percentage))); drawbar=int((widthbar*percentage)/100) locate ybar+1,xbar+6:color 1,1:print repeat$(drawbar,chr$(32)); if (widthbar-drawbar)<>1 then color 11,0:print repeat$(widthbar-drawbar,chr$(254)); color 9:print chr$(179); end if color 9,0:locate ybar+2,xbar print chr$(192)repeat$(widthbar+5,chr$(196))chr$(217); EXITBAR: locate oldy,oldx:color fore%,back% tempbar$="":tempbar=0:tempbarlength=0 drawbar=0:percentage=0:ybar=0:xbar=0 END SUB