home *** CD-ROM | disk | FTP | other *** search
- '**********************************ADDNUM.BAS**************************
- 'JRD NOTE:
- '
- 'For adding numbers to QuickBASIC programs that need to be debugged
- 'Not sure if when you compile using the "/d" switch with BC.EXE
- 'that the line number that it reports is the same one that this program
- 'puts in.
- '
- 'Because I was not happy having to manually remove the line numbers from
- 'TYPE..... END TYPE, and SELECT CASE..... END SELECT,
- 'I added the SUB SkipKeyWord$ (a$, KeyWordFlag%) which parses those words
- 'and sets "Flags" so that the line count continues but the line number
- 'is not added. It's not great code, but it works.
- '
- '
- '
- ' Mon 04-04-1994 00:22:47
- '
- 'John De Palma on CompuServe 76076,571
- '
- DEFINT A-Z
- '$INCLUDE: 'qb.bi'
- DECLARE SUB LocateIt (Row%, text$)
- DECLARE SUB Splash (BackGround%)
- DECLARE SUB TextBoxShadow (Row%, Col%, Message$, Outline%, Shadow%, Length%)
- DECLARE SUB Waitkey ()
- DECLARE SUB CursorOff ()
- DECLARE SUB CursorOn ()
- DECLARE SUB ParseFileName (FileName$, Drive$, File$, Ext$)
- DECLARE FUNCTION Center% (text$)
- DECLARE FUNCTION BufferedKeyInput$ (n%)
- DECLARE FUNCTION Exist% (Spec$)
- DECLARE SUB ErrorBox (Row%)
- DECLARE SUB SetBorder (ColrByte%)
- DECLARE SUB TwoColrs (Fgd%, Bkg%, Colr%)
- DECLARE SUB ColorIt (Fgd%, Bkg%)
- DECLARE SUB SkipKeyWord (a$, KeyWordFlag%)
- DECLARE SUB FileProgress (Counter&, LineNum&, Row%, Col%)
- COMMON SHARED KeyWordFlag%
-
- DIM Count AS LONG
- DIM SHARED Regs AS RegType
- REDIM SHARED Box$(1 TO 56)
- Copyright$ = "■Copyright (c) 1994 LearnWare (c) ■ John De Palma■"
-
- Again:
- KeyWordFlag% = False
- COLOR 7, 1
- SCREEN 0
- WIDTH 80, 25
- CLS
- CALL Splash(179)
- CALL SetBorder(2)
-
- Col% = 0
- Length% = 0
-
- COLOR 15, 1
- Message$ = "Program to Add Line Numbers to *.BAS Code"
- COLOR 15, 7
- CALL TextBoxShadow(1, Col%, Message$, 4, 1, Length%)
- COLOR 15, 1
- text$ = " File Name "
- Message$ = SPACE$(LEN(text$))
- CALL TextBoxShadow(6, Col%, Message$, 6, 1, Length%)
- CALL LocateIt(6, text$)
- LOCATE 7, 41 - 6
- CursorOn
- FileName$ = BufferedKeyInput(12)
- FileName$ = RTRIM$(LTRIM$(FileName$))
- CursorOff
-
- IF NOT Exist%(FileName$) THEN
- CALL ErrorBox(11)
- BEEP
- PRINT
- PRINT
- Message$ = "Whoa... Can't Find: " + UCASE$(FileName$)
- COLOR 12, 4
- CALL TextBoxShadow(16, Col%, Message$, 3, 0, Length%)
- Message$ = "PRESS {Enter} to try Again... <Esc> to EXIT!"
- COLOR 11, 2
- CALL TextBoxShadow(20, Col%, Message$, 1, 1, Length%)
- Waitkey
- GOTO Again
- END IF
-
- CALL ParseFileName(FileName$, Drive$, File$, Ext$)
- CursorOff
- NewFile$ = File$ + ".LIN"
-
-
-
- text$ = " What START Number (1, 10...) "
- LOCATE 10, 2: PRINT text$
- Message$ = SPACE$(3)
- COLOR 14, 1
- CALL TextBoxShadow(11, 20, Message$, 5, 1, Length%)
- LOCATE 12, 22
- CursorOn
- Start$ = BufferedKeyInput(3)
- IF Start$ = "" THEN Start$ = "1"
- Start% = VAL(Start$)
- CursorOff
-
- COLOR 15, 1
- text$ = " What Number INTERVAL (1, 5, 10....) "
- LOCATE 10, 42: PRINT text$
- Message$ = SPACE$(2)
- COLOR 13, 1
- CALL TextBoxShadow(11, 50, Message$, 5, 1, Length%)
- LOCATE 12, 52
- CursorOn
- Interval$ = BufferedKeyInput(2)
- IF Interval$ = "" THEN Interval$ = "1"
- Interval% = VAL(Interval$)
- CursorOff
-
- FileNumber1 = FREEFILE
- OPEN FileName$ FOR INPUT AS #FileNumber1
- WHILE NOT EOF(FileNumber1)
- LINE INPUT #FileNumber1, a$
- Counter& = Counter& + 1
- WEND
- CLOSE FileNumber1
-
- FileNumber1 = FREEFILE
- OPEN FileName$ FOR INPUT AS #FileNumber1
-
- FileNumber2 = FREEFILE
- OPEN NewFile$ FOR OUTPUT AS #FileNumber2
-
- Count& = Start%
- LineNum& = 0
-
- Message$ = SPACE$(44)
- COLOR 14, 6
- CALL TextBoxShadow(15, 0, Message$, 4, 1, Length%)
- COLOR 15, 1
-
- WHILE NOT EOF(FileNumber1)
-
- LINE INPUT #FileNumber1, a$
- CALL SkipKeyWord(a$, KeyWordFlag%)
- IF KeyWordFlag% THEN
- PRINT #FileNumber2, SPACE$(LEN(Count&)); " "; a$
- ELSE
- PRINT #FileNumber2, LTRIM$(STR$(Count&)); " "; a$
- END IF
- Count& = Count& + Interval%
- LineNum& = LineNum& + 1
- text$ = "Processing line " + STR$(LineNum&)
- LOCATE 16, 19: PRINT text$
- CALL FileProgress(Counter&, LineNum&, 16, 43)
- WEND
- CLOSE
- BEEP
- Message$ = "The New File - " + UCASE$(NewFile$) + " - is DONE!"
- COLOR 15, 2
- CALL TextBoxShadow(20, 0, Message$, 1, 1, Length%)
- Waitkey
- COLOR 7, 0
- END
-
- 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 ColorIt (Fgd, Bkg)
- COLOR Fgd, Bkg
- END SUB
-
- SUB CursorOff
- LOCATE , , 0
- END SUB
-
- SUB CursorOn
- LOCATE , , 1, 4, 7
- END SUB
-
- SUB ErrorBox (Row%)
-
- CALL ColorIt(14, 4)
- OldRow% = CSRLIN
- OldCol% = POS(0)
- text$ = "█▀▀▀▀▀▀▀▀▀▀▀▀▀█"
- CALL LocateIt(Row%, text$)
- text$ = "█ █"
- CALL LocateIt(Row% + 1, text$)
- text$ = "█▄▄▄▄▄▄▄▄▄▄▄▄▄█"
- CALL LocateIt(Row% + 2, text$)
- text$ = "ERROR"
- CALL ColorIt(15 + 16, 4)
- CALL LocateIt(Row% + 1, text$)
- LOCATE OldRow%, OldCol%
- END SUB
-
- FUNCTION Exist% (Spec$) STATIC 'reports if a file exists
-
- 'From Ethan's 1992 Book, shorter than 1991 code
-
- DIM DTA AS STRING * 44 'This is DOS' work area
- 'DIM Regs AS RegType 'Used by CALL Interrupt
- DIM LocalSpec AS STRING * 80 'Using a fixed-length string
- ' supports both QB and PDS
- LocalSpec$ = Spec$ + CHR$(0) 'Add a CHR$(0) for DOS
-
- Exist% = True 'Assume the file is present
-
-
- Regs.ax = &H1A00 'Assign DTA service
- Regs.dx = VARPTR(DTA) 'Show DOS where to place it
- CALL INTERRUPT(&H21, Regs, Regs)
-
- Regs.ax = &H4E00 'Find first matching file
- Regs.cx = 39 'Any file attribute okay
- Regs.dx = VARPTR(LocalSpec)
- CALL INTERRUPT(&H21, Regs, Regs) 'See if there's a match
-
- IF Regs.flags AND 1 THEN 'If the Carry flag is set
- Exist% = False ' there were no matches
-
- ELSEIF Regs.ax <> 0 THEN 'or if AX contains an Error
- Exist% = 0 'number (usually &H12)
-
- ELSEIF Regs.ax = 0 THEN 'else file exists
- Exist% = True
-
- ELSE
-
- END IF
-
- END FUNCTION
-
- SUB FileProgress (Counter&, LineNum&, Row%, Col%)
- STATIC Fraction&, Flag%, Num%, PerCent&
-
- SaveRow% = CSRLIN
- SaveCol% = POS(0)
-
- LOCATE Row%, Col%
- IF Flag% = True THEN GOTO Around
- BackGround$ = STRING$(20, 176)
- PRINT BackGround$
- Fraction& = (Counter& \ 20)
- PerCent& = Fraction&
- Num% = 1
- Flag% = True
- Around:
- 'Fraction& = 5
- IF Fraction& = LineNum& THEN
- LOCATE Row, Col%
- LOCATE Row, Col%
- PRINT STRING$(Num%, 219)
- Num% = Num% + 1
- Fraction& = Fraction& + PerCent&
- END IF
-
- LOCATE SaveRow%, SaveCol%
-
- 'single line box
- ' Box$(1) = "┌"
- ' Box$(2) = "─"
- ' Box$(3) = "┐"
- ' Box$(4) = "│"
- ' Box$(5) = "│"
- ' Box$(6) = "└"
- ' Box$(7) = "─"
- ' Box$(8) = "┘"
-
-
- END SUB
-
- SUB LocateIt (Row%, text$)
- LOCATE Row%, Center(text$)
- PRINT text$;
- END SUB
-
- SUB ParseFileName (FileName$, Drive$, File$, Ext$) STATIC
-
- Length% = LEN(FileName$)
-
- ' first get the drive
-
- colon = INSTR(FileName$, ":")
- IF colon THEN
- Drive$ = LEFT$(FileName$, colon)
- END IF
-
- ' next erase a final backslash if it exists
-
- IF RIGHT$(FileName$, 1) = "\" THEN
- temp$ = LEFT$(FileName$, Length% - 1)
- Length% = Length% - 1
- ELSE
- temp$ = FileName$
- END IF
-
- ' third get the Extension
-
- FOR Num% = Length% TO 1 STEP -1
-
- Ext$ = MID$(temp$, Num%)
- IF INSTR(Ext$, ".") THEN
- Ext$ = LTRIM$(LEFT$(Ext$, 4))
- temp$ = LEFT$(temp$, Num% - 1)
- k = Num%
- EXIT FOR
- ELSE
- Ext$ = ""
- k = Length% 'if there is no extension
- END IF
- NEXT Num%
-
- 'fourth get the file name but not more than 8 letters...
-
- FOR Num% = k TO 1 STEP -1
- File$ = MID$(temp$, Num%)
- IF INSTR(File$, "\") THEN
- EXIT FOR
- ELSE
- File$ = MID$(temp$, Num%)
- 'IF LEN(File$) >= 8 THEN EXIT FOR
- END IF
- NEXT Num%
- File$ = LEFT$(File$, 8)
-
- 'fifth add a backslash to the file name
- 'use for full path, only, not now....
- 'IF INSTR(File$, "\") = 0 THEN
- ' File$ = "\" + File$
- 'END IF
-
- END SUB
-
- SUB SetBorder (ColrByte%) STATIC
-
- 'DIM Regs AS RegType
- Regs.ax = &H1001
- Regs.bx = ColrByte% * &H100
- CALL INTERRUPT(&H10, Regs, Regs)
-
- END SUB
-
- SUB SkipKeyWord (a$, KeyWordFlag%)
- STATIC TypeFlagTrue%, b$
-
- b$ = UCASE$(a$)
-
- FOR i% = 1 TO LEN(b$)
- IF MID$(b$, i%, 1) = "'" THEN
- KeyWordFlag% = False
- EXIT FOR
- ELSEIF MID$(b$, i%, 1) = CHR$(13) THEN
- KeyWordFlag% = False
- EXIT FOR
- ELSEIF MID$(b$, i%, 1) = "R" THEN
- j% = i%
- FOR j% = j% TO j% + 2
- Word$ = Word$ + MID$(b$, j%, 1)
- NEXT
- IF Word$ = "REM" THEN
- KeyWordFlag% = False
- END IF
- EXIT FOR
- ELSEIF MID$(b$, i%, 1) = "T" THEN
- j% = i%
- FOR j% = j% TO j% + 3
- Word$ = Word$ + MID$(b$, j%, 1)
- NEXT
- IF Word$ = "TYPE" THEN
- KeyWordFlag% = True
- TypeFlagTrue% = True
- END IF
- EXIT FOR
- ELSEIF MID$(b$, i%, 1) = "S" THEN
- j% = i%
- FOR j% = j% TO j% + 10
- Word$ = Word$ + MID$(b$, j%, 1)
- NEXT
- IF Word$ = "SELECT CASE" THEN
- KeyWordFlag% = True
- TypeFlagTrue% = True
- END IF
- EXIT FOR
- ELSEIF MID$(b$, i%, 1) = "E" THEN
- j% = i%
- FOR j% = j% TO j% + 9
- Word$ = Word$ + MID$(b$, j%, 1)
- NEXT
- IF LTRIM$(Word$) = "END TYPE" OR LTRIM$(Word$) = "END SELECT" THEN
- KeyWordFlag% = True
- TypeFlagTrue% = False
- END IF
- EXIT FOR
- ELSE
- IF TypeFlagTrue% THEN
- KeyWordFlag% = True
- ELSE
- KeyWordFlag% = False
- END IF
- END IF
- NEXT
- END SUB
-
- SUB Splash (BackGround%) STATIC
- STATIC ColrFlag%
- RANDOMIZE TIMER
- IF ColrFlag% AND BackGround% THEN
- UpperBound = 254
- LowerBound = 176
- Char = INT((UpperBound - LowerBound + 1) * RND + LowerBound)
- ELSEIF BackGround% THEN
- Char = BackGround%
- ELSE
- Char = 176
- END IF
- CLS
- FOR i = 1 TO 25
- LOCATE i, 1
- PRINT STRING$(80, Char);
- NEXT
- ColrFlag% = True
- END SUB
-
- SUB TextBoxShadow (Row%, Col%, Message$, Outline%, Shadow%, Length%)
- 'Will put a message into a three line box -or-
- 'draw a box without a message using Message$=SPACE$(x)
- 'where "x" is the width of the box and Length%= number of lines > 3
- 'Boxes are centered if Col% = 0; else left side of box = Col%.
- 'Boxes display a true shadow if Shadow% <> 0
- 'True = -1: False = 0
-
- STATIC BoxReadFlag
- Message$ = LEFT$(Message$, 60)
- BoxWidth% = LEN(Message$) + 4
- SELECT CASE Outline%
- CASE 0
- j = 8 * 6 + 1
- CASE 1
- j = 1
- CASE 2
- j = 8 + 1
- CASE 3
- j = 8 * 2 + 1
- CASE 4
- j = 8 * 3 + 1
- CASE 5
- j = 8 * 4 + 1
- CASE 6
- j = 8 * 5 + 1
- CASE ELSE
- j = 8 * 6 + 1
- END SELECT
-
- IF BoxReadFlag THEN GOTO Skip
- REDIM Box$(1 TO 56)
- BoxReadFlag = True
-
- 'single line box
- Box$(1) = "┌"
- Box$(2) = "─"
- Box$(3) = "┐"
- Box$(4) = "│"
- Box$(5) = "│"
- Box$(6) = "└"
- Box$(7) = "─"
- Box$(8) = "┘"
-
- 'double top box
- Box$(9) = "╒"
- Box$(10) = "═"
- Box$(11) = "╕"
- Box$(12) = "│"
- Box$(13) = "│"
- Box$(14) = "╘"
- Box$(15) = "═"
- Box$(16) = "╛"
-
- 'double side box
- Box$(17) = "╓"
- Box$(18) = "─"
- Box$(19) = "╖"
- Box$(20) = "║"
- Box$(21) = "║"
- Box$(22) = "╙"
- Box$(23) = "─"
- Box$(24) = "╜"
-
- 'double box
- Box$(25) = "╔"
- Box$(26) = "═"
- Box$(27) = "╗"
- Box$(28) = "║"
- Box$(29) = "║"
- Box$(30) = "╚"
- Box$(31) = "═"
- Box$(32) = "╝"
-
- 'bold box
- Box$(33) = "█"
- Box$(34) = "▀"
- Box$(35) = "█"
- Box$(36) = "█"
- Box$(37) = "█"
- Box$(38) = "█"
- Box$(39) = "▄"
- Box$(40) = "█"
-
- 'bold and thick box
- Box$(41) = "█"
- Box$(42) = "█"
- Box$(43) = "█"
- Box$(44) = "█"
- Box$(45) = "█"
- Box$(46) = "█"
- Box$(47) = "█"
- Box$(48) = "█"
-
- 'no box
- Box$(49) = " "
- Box$(50) = " "
- Box$(51) = " "
- Box$(52) = " "
- Box$(53) = " "
- Box$(54) = " "
- Box$(55) = " "
- Box$(56) = " "
-
- Skip:
-
- IF Col% = 0 THEN
-
- BoxText$ = Box$(j) + STRING$(BoxWidth%, Box$(j + 1)) + Box$(j + 2)
- CALL LocateIt(Row%, BoxText$)
- Row2% = CSRLIN: Col2% = POS(0)
- Colr% = SCREEN(Row2%, Col2% - 1, 1)
- CALL TwoColrs(Fgd%, Bkg%, Colr%)
-
- FOR i = 1 TO Length% + 1
- BoxText$ = Box$(j + 3) + " " + Message$ + " " + Box$(j + 4)
- CALL LocateIt(Row% + i, BoxText$)
-
- IF Shadow% THEN
- COLOR 7, 0
- FOR k = 1 TO 2
- PRINT CHR$(SCREEN(CSRLIN, POS(0)));
- NEXT
- COLOR Fgd%, Bkg%
- END IF
- NEXT i
-
- BoxText$ = Box$(j + 5) + STRING$(BoxWidth%, Box$(j + 6)) + Box$(j + 7)
- CALL LocateIt(Row% + i, BoxText$)
-
- IF Shadow% THEN
- COLOR 7, 0
- FOR k = 1 TO 2
- PRINT CHR$(SCREEN(CSRLIN, POS(0)));
- NEXT
- 'COLOR Fgd%, Bkg%
-
- COLOR 7, 0
- LOCATE Row% + i + 1, Center(BoxText$) + 2
-
- FOR k = 1 TO BoxWidth% + 2
- PRINT CHR$(SCREEN(CSRLIN, POS(0)));
- NEXT
- COLOR Fgd%, Bkg%
- END IF
- ELSE
-
- BoxText$ = Box$(j) + STRING$(BoxWidth%, Box$(j + 1)) + Box$(j + 2)
- LOCATE Row%, Col%
- PRINT BoxText$;
- Row2% = CSRLIN: Col2% = POS(0)
- Colr% = SCREEN(Row2%, Col2% - 1, 1)
- CALL TwoColrs(Fgd%, Bkg%, Colr%)
-
- FOR i = 1 TO Length% + 1
- BoxText$ = Box$(j + 3) + " " + Message$ + " " + Box$(j + 4)
- LOCATE Row% + i, Col%
- PRINT BoxText$;
-
- IF Shadow% THEN
- COLOR 7, 0
- FOR k = 1 TO 2
- PRINT CHR$(SCREEN(CSRLIN, POS(0)));
- NEXT
- COLOR Fgd%, Bkg%
- END IF
-
- NEXT i
-
- BoxText$ = Box$(j + 5) + STRING$(BoxWidth%, Box$(j + 6)) + Box$(j + 7)
- LOCATE Row% + i, Col%
- PRINT BoxText$;
-
- IF Shadow% THEN
- COLOR 7, 0
- FOR k = 1 TO 2
- PRINT CHR$(SCREEN(CSRLIN, POS(0)));
- NEXT
- 'COLOR Fgd%, Bkg%
- 'COLOR 7,0
- LOCATE Row% + i + 1, Col% + 2
- FOR k = 1 TO BoxWidth% + 2
- PRINT CHR$(SCREEN(CSRLIN, POS(0)));
- NEXT
- COLOR Fgd%, Bkg%
- END IF
-
- END IF
-
- END SUB
-
- SUB TwoColrs (Fgd%, Bkg%, Colr%)
-
- Fgd% = (Colr% AND 128) \ 8 + (Colr% AND 15)
- Bkg% = (Colr% AND 112) \ 16
-
- END SUB
-
- SUB Waitkey
-
- WHILE INKEY$ <> "": WEND
- DO
- kee$ = INKEY$
- LOOP UNTIL LEN(kee$)
- IF kee$ = CHR$(27) THEN END
-
- END SUB
-
-