home *** CD-ROM | disk | FTP | other *** search
- '******************************BUFFKEY.BAS******************************
- '
- ' Sat 03-19-1994 12:30:55
- '
- 'QuickBASIC 4.5 has few and -terrible- keyboard input commands
- 'if you want to control the user's input. Part of my uphill
- 'struggle with this language has been... and continues to be that
- 'problem.
- '
- 'So.... as I try to learn about Assembly, I realize that Assembly
- 'is WORSE!!! Far worse, but... MS-DOS does have a little interrupt
- 'function that allows you to enter keystrokes of up to 253 characters
- 'and EDIT them using the MS-DOS editing keys (left cursor key,
- 'the backspace key...). You set the number of key strokes and if the
- 'user exceeds them, the computer beeps and does not permit another
- 'key stroke.... Gorsh.... error detection!
- '
- 'So that is what BUFFKEY.BAS does. It uses the Function &HA in AX with
- 'Interrupt &H21 to do that. See BUFFKEY.TXT for a more lucid story....
- '
- ' ╔════════════════════════════════════════════════════════╗
- ' ║ ║
- ' ║ BUFFKEY.BAS is a slick and simple line editor! ║
- ' ║ ║
- ' ╚════════════════════════════════════════════════════════╝
- '
- 'REFERENCES:
- '
- '1. Norton's PC Programming Bible, 1993, Microsoft Press
- '2. QuickBasic Programming Toolbox, JJ Craig, 1991, Microsoft Press
- '
- 'John De Palma on CompuServe 76076,571
- '
- '===============================END TEXT================================
-
- 'Declarations
- DEFINT A-Z
- DECLARE FUNCTION BufferedKeyInput$ (n%)
- DECLARE SUB TextBox (Row%, Col%, Message$, Outline%, Length%)
- DECLARE FUNCTION Center% (text$)
- DECLARE SUB LocateIt (Row%, text$)
- '$INCLUDE: 'johns.bi'
-
- 'Executable code follows
- Row% = 6
- n% = 12
- COLOR 15, 1
- CLS
-
- COLOR 14, 4
- Message$ = "Buffered Key Input ala MS-DOS!"
- CALL TextBox(Row% - 4, 0, Message$, 4, 0)
-
-
- COLOR 15, 4
- Message$ = SPACE$(n%)
- CALL TextBox(Row%, 0, Message$, 5, 0)
- text$ = "PRESS: {Enter}"
- COLOR 12, 4
- CALL LocateIt(Row%, text$)
- text$ = "to END edit"
- CALL LocateIt(Row% + 2, text$)
- COLOR 11, 0
- CALL LocateIt(Row% + 1, Message$)
- LOCATE Row% + 1, Center%(Message$)
- Strg$ = BufferedKeyInput$(n%)
-
- BoxWidth% = LEN(Strg$)
- Message$ = SPACE$(BoxWidth%)
- COLOR 15, 2
- CALL TextBox(Row% + 6, 0, Message$, 3, 0)
- COLOR 11, 0
- CALL LocateIt(Row% + 7, Strg$)
-
- WHILE INKEY$ <> "": WEND
- WHILE INKEY$ = "": WEND
-
- 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 LocateIt (Row%, text$)
- LOCATE Row%, Center(text$)
- PRINT text$;
- END SUB
-
- SUB TextBox (Row%, Col%, Message$, Outline%, 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
- 'All boxes are centered.
- 'Now to make them non centered....
-
- Message$ = LEFT$(Message$, 60)
- BoxWidth% = LEN(Message$) + 4
- SELECT CASE Outline%
- CASE 0
- j = 8 * 5 + 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 ELSE
- j = 8 * 5 + 1
- END SELECT
-
- REDIM Box$(1 TO 8 * 6)
-
- '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 and thick box
- Box$(33) = "█"
- Box$(34) = "▀"
- Box$(35) = "█"
- Box$(36) = "█"
- Box$(37) = "█"
- Box$(38) = "█"
- Box$(39) = "▄"
- Box$(40) = "█"
-
- 'no box
- Box$(41) = " "
- Box$(42) = " "
- Box$(43) = " "
- Box$(44) = " "
- Box$(45) = " "
- Box$(46) = " "
- Box$(47) = " "
- Box$(48) = " "
-
- IF Col% = 0 THEN
-
- BoxText$ = Box$(j) + STRING$(BoxWidth%, Box$(j + 1)) + Box$(j + 2)
- CALL LocateIt(Row%, BoxText$)
-
- FOR i = 1 TO Length% + 1
- BoxText$ = Box$(j + 3) + " " + Message$ + " " + Box$(j + 4)
- CALL LocateIt(Row% + i, BoxText$)
- NEXT i
-
- BoxText$ = Box$(j + 5) + STRING$(BoxWidth%, Box$(j + 6)) + Box$(j + 7)
- CALL LocateIt(Row% + i, BoxText$)
-
- ELSE
-
- BoxText$ = Box$(j) + STRING$(BoxWidth%, Box$(j + 1)) + Box$(j + 2)
- LOCATE Row%, Col%
- PRINT BoxText$
-
- FOR i = 1 TO Length% + 1
- BoxText$ = Box$(j + 3) + " " + Message$ + " " + Box$(j + 4)
- LOCATE Row% + i, Col%
- PRINT BoxText$
- NEXT i
-
- BoxText$ = Box$(j + 5) + STRING$(BoxWidth%, Box$(j + 6)) + Box$(j + 7)
- LOCATE Row% + i, Col%
- PRINT BoxText$
-
- END IF
- END SUB
-
-