home *** CD-ROM | disk | FTP | other *** search
- '*****************************GAUGEBAR.BAS********************************
- '
- 'JRD NOTE:
- '
- 'Makes a gauge bar, similar to Norton's Utilities Format gauge bar.
- 'Not identical as this is written in QuickBASIC and I didn't spend a lot
- 'of time verifying that all numbers work.
- 'Since floating point numbers (single and double precision) are slower
- 'and take more memory; made the BarGraph SUB with LONG integers. That
- 'means that for some graph lengths "100%" will fall short or long of the
- 'bar length... but, GAUGEBAR.BAS is better than nothing... which is
- 'why I made this program. I needed it and there was nothing out there.
- '
- 'First attempt with this weirdness was in my file ADDNUM.BAS
- 'The correct way is to include the BarGraph SUB as part of loop that does
- 'the work. See ADDNUM.BAS, a classic use of this little trick.
- '
- 'Another program I had to make 'cause I couldn't find it anywhere...
- '
- 'Can use to makes a "File Read" or any other kind of gauge bar
- '
- 'Can simulate a process by using the Pause2 time delay
- '
- '
- 'John De Palma on CompuServe 76076,571
- '
- '4/6/94
- '
- DEFINT A-Z
- ' $INCLUDE: 'qb.bi'
- DECLARE SUB Pause2 ()
- DECLARE SUB Pause (Seconds!)
- DECLARE SUB BarGraph (Counter&, LineNum&, BarLength%, Row%, Col%)
- DECLARE SUB DrawBarGraph (Row%, Col%, BarLength%)
- DECLARE SUB TimedBarGraph (Seconds!, BarLength%, Row%, Col%)
- DECLARE SUB LocateIt (Row%, Text$)
- DECLARE SUB WaitKey ()
- DECLARE SUB CursorOff ()
- DECLARE SUB CursorOn ()
-
- DECLARE FUNCTION Center% (Text$)
- DECLARE FUNCTION BufferedKeyInput$ (n%)
-
- DIM SHARED Regs AS RegType
- 'CONST False = 0 'these are in QB.BI
- 'CONST True = -1
-
- Copyright$ = "■Copyright (c) 1994 LearnWare (c) ■ John De Palma■"
- Counter& = 1000 'using LONG on purpose
- LineNum& = 1 'see ADDNUM.BAS
- BarLength% = 33 'default
- Row% = 14
- Col% = 0 'centers on screen, I did =NOT= check code for
- COLOR 15, 1 'non centered placement of the gauge-bar
- SCREEN 0 'this was tough enough
- WIDTH 80, 25
- CLS
-
- Text$ = "How Long a Gauge-Bar? (15 to 50)"
- CALL LocateIt(4, Text$)
- Text$ = SPACE$(2)
- COLOR 11, 0
- CALL LocateIt(6, Text$)
- CursorOn
- LOCATE 6, Center%(Text$)
- Bar$ = BufferedKeyInput$(2)
- CursorOff
- BarLength% = VAL(Bar$)
- IF BarLength% > 50 THEN BarLength% = 50
-
- Text$ = "How Many SECONDS to Run (1 to 30)"
- COLOR 14, 1
- CALL LocateIt(10, Text$)
- Text$ = SPACE$(2)
- COLOR 11, 0
- CALL LocateIt(12, Text$)
- CursorOn
- LOCATE 12, Center%(Text$)
- Seconds$ = BufferedKeyInput$(2)
- CursorOff
- Seconds! = VAL(Seconds$)
-
- CALL TimedBarGraph(Seconds!, BarLength%, Row%, Col%)
-
- Text$ = "Now to see a 'File Read' Version"
- CALL LocateIt(18, Text$)
- Text$ = "press a Key.... or <Esc> to EXIT"
- CALL LocateIt(19, Text$)
- WaitKey
-
- CLS
- Text$ = "How Long a Gauge-Bar? (15 to 50)"
- CALL LocateIt(4, Text$)
- Text$ = SPACE$(2)
- COLOR 11, 0
- CALL LocateIt(6, Text$)
- CursorOn
- LOCATE 6, Center%(Text$)
- Bar$ = BufferedKeyInput$(2)
- CursorOff
- 'STOP
- BarLength% = VAL(Bar$)
- IF BarLength% > 50 THEN BarLength% = 50
-
- Text$ = "FAST(1) Medium(2) or Slow(3) (1, 2, or 3)"
- COLOR 14, 1
- CALL LocateIt(10, Text$)
- Text$ = SPACE$(1)
- COLOR 11, 0
- CALL LocateIt(12, Text$)
- CursorOn
- LOCATE 12, Center%(Text$)
- Seconds$ = BufferedKeyInput$(1)
- IF Seconds$ = "" THEN Seconds$ = "2"
- CursorOff
- Seconds! = VAL(Seconds$)
- Col% = 0
-
- 'this next piece simulates a file read. You call the BarGraph
- 'SUB each time you read a file line... After first finding out
- 'how many lines are in the file and setting that to Counter&
- 'see ADDNUM.BAS for this code example
-
- FOR i = 1 TO Counter&
- CALL BarGraph(Counter&, LineNum&, BarLength%, Row%, Col%)
- LineNum& = LineNum& + 1 'simulates reading a file in a loop
- IF Seconds! = 1 THEN 'no pause, just loops and runs
- ELSEIF Seconds! = 2 THEN 'these time pauses are here for demo only!
- PLAY "p64" 'the shortest pause of .015625 seconds
- ELSE
- Pause2 'pauses for about .054945 seconds or less
- END IF
- NEXT
- Pause (2)
- COLOR 11, 0
- LOCATE Row% + 4, 40: PRINT "DONE!"
- WaitKey
- COLOR 7, 0
-
- SUB BarGraph (Counter&, LineNum&, BarLength%, Row%, Col%)
- STATIC Fraction&, Num%, PerCent&, DrawFlag%, SaveRow%, SaveCol%
-
- IF DrawFlag% = True THEN GOTO SkipDraw
- SaveRow% = CSRLIN
- SaveCol% = POS(0)
- CALL DrawBarGraph(Row%, Col%, BarLength%)
- DrawFlag% = True
- IF BarLength% >= Counter& THEN EXIT SUB
- Fraction& = Counter& / BarLength%
- PerCent& = Fraction&
- Num% = 1
-
- SkipDraw:
-
- IF Fraction& = LineNum& THEN
- COLOR 15, 4
- LOCATE Row% + 1, Col% + 2
- PRINT STRING$(Num%, " ")
- LOCATE Row% + 1, Col% + (BarLength% \ 2) + 1
- COLOR 15, 4
- PRINT LEFT$(LTRIM$(STR$(Fraction& / 10)), 2) + "%"
- Num% = Num% + 1
- Fraction& = Fraction& + PerCent&
- IF Fraction& >= Counter& - 1 THEN
- LOCATE Row% + 1, Col% + (BarLength% \ 2) + 1
- PRINT "100%"
- LOCATE SaveRow%, SaveCol%
- END IF
- COLOR 15, 1
- END IF
-
- END SUB
-
- FUNCTION BufferedKeyInput$ (n%) STATIC
-
- 'DIM Regs AS RegType
- b$ = CHR$(n% + 1) + SPACE$(n% + 1) + CHR$(13) 'see EXPLANATION
-
- Regs.ax = &HA00 'BufferkeyInput MS-DOS Function
- Regs.ds = VARSEG(b$) 'segment of string b$
- Regs.dx = SADD(b$) 'offset of string b$
- 'using qb.bi INCLUDE file
- CALL INTERRUPTX(&H21, Regs, Regs)
- count% = ASC(MID$(b$, 2, 1)) 'length of the string b$
-
- 'EXPLANATION of b$ command
- 'byte one of b$ contains the working -size- of the string.
- 'byte two is the -actual size- of the string that MS-DOS uses.
- 'last byte is a carriage return which is needed to prevent
- 'a STRING SPACE CORRUPT Run Time error when you use this
- 'so the return string starts at byte three (3), and does NOT
- 'include the carriage return
- 'see below
- BufferedKeyInput$ = MID$(b$, 3, count%)
-
- END FUNCTION
-
- FUNCTION Center% (Text$)
- Center% = 41 - LEN(Text$) \ 2
- END FUNCTION
-
- SUB CursorOff
- LOCATE , , 0
- END SUB
-
- SUB CursorOn
- LOCATE , , 1, 4, 7
- END SUB
-
- SUB DrawBarGraph (Row%, Col%, BarLength%)
-
- 'SaveRow% = CSRLIN
- 'SaveCol% = POS(0)
- 'got to have the next to display "Percent Completed"
- IF BarLength% <= 15 THEN BarLength% = 15
- BackGround$ = STRING$(BarLength%, 176)
- IF Col% = 0 THEN
- Col% = 41 - ((BarLength% + 4) \ 2)
- END IF
- 'single line box
- LOCATE Row%, Col%
- PRINT "┌Percent Completed" + STRING$(BarLength% - 15, "─") + "┐"
- LOCATE Row% + 1, Col%
- PRINT "│" + SPACE$(BarLength% + 2) + "│"
- LOCATE Row% + 2, Col%
- PRINT "└" + STRING$(BarLength% + 2, "─") + "┘"
- LOCATE Row% + 1, Col% + 2
- COLOR 15, 0
- PRINT BackGround$
- COLOR 15, 1
- 'LOCATE SaveRow%, SaveCol%
-
- END SUB
-
- SUB LocateIt (Row%, Text$)
- LOCATE Row%, Center(Text$)
- PRINT Text$;
- END SUB
-
- SUB Pause (Seconds!)
-
- Synch! = TIMER
- DO 'looping changes the Start! time to
- Start! = TIMER 'synchronize to the system timer
- LOOP WHILE Start! = Synch! 'Seconds! must be SINGLE to get fractions
- 'of a second
- DO
- kee$ = INKEY$
- LOOP UNTIL TIMER > (Start! + Seconds!) OR LEN(kee$)
-
- 'put Kee$ in just in case we pass midnight
- WHILE INKEY$ <> "": WEND 'delete that key stroke
- END SUB
-
- SUB Pause2
-
- Synch! = TIMER
- DO 'looping changes the Start! time to
- Start! = TIMER 'synchronize to the system timer
- LOOP WHILE Start! = Synch! 'Seconds! must be SINGLE to get fractions
- 'normally used to synch a timer
- 'in this case, the briefest pause
- END SUB 'about .054945 seconds or less
-
- SUB TimedBarGraph (Seconds!, BarLength%, Row%, Col%)
- STATIC Fraction!, Num%, PerCent!, DrawFlag%, SaveRow%, SaveCol%
-
- IF DrawFlag% = True THEN GOTO SkipDraw2
- SaveRow% = CSRLIN
- SaveCol% = POS(0)
- CALL DrawBarGraph(Row%, Col%, BarLength%)
- DrawFlag% = True
- 'STOP
- BarLength! = BarLength%
- Fraction! = Seconds! / BarLength%
- PerCent! = Fraction!
- Number! = 100 / BarLength!
- AddPerCent! = Number!
- Num% = 1
-
- SkipDraw2:
- DO
-
- Start! = TIMER 'synchronize to the system timer
- DO
-
- LOOP UNTIL TIMER >= (Start! + PerCent!)
-
- COLOR 15, 4
- LOCATE Row% + 1, Col% + 2
- PRINT STRING$(Num%, " ")
- LOCATE Row% + 1, Col% + (BarLength% \ 2)
- COLOR 15, 4
- PRINT LEFT$(LTRIM$(STR$(Number!)), 2) + "%"
- Num% = Num% + 1
- Number! = Number! + AddPerCent!
- Fraction! = Fraction! + PerCent!
- IF Fraction! >= Seconds! THEN
- LOCATE Row% + 1, Col% + (BarLength% \ 2)
- PRINT " 100% "
- LOCATE SaveRow%, SaveCol%
- END IF
- COLOR 15, 1
- LOOP WHILE Fraction! < Seconds!
- END SUB
-
- SUB WaitKey
-
- WHILE INKEY$ <> "": WEND
- DO
- kee$ = INKEY$
- LOOP UNTIL LEN(kee$)
- IF kee$ = CHR$(27) THEN END
-
- END SUB
-
-