home *** CD-ROM | disk | FTP | other *** search
- ' INPT.BAS
- ' This subprogram accepts input from allowable characters
- ' in string valid$ starting at row r% and column c%. The
- ' input is echoed to the screen with attribute type%.
- ' The maximum allowable string size is passed in nc%.
- ' The insert, delete, left and right arrow, backspace, enter,
- ' and escape keys are active. The escape key returns the input
- ' string to what was originally on the screen at the time the
- ' INPT routine was called.
-
- SUB inpt(r%, c%, type%, nc%, valid$, sc%) STATIC
-
- ' r% and c% are the row and column locations where input starts
- ' type% is the screen attribute used throughout the input length
- ' nc% is the maximum allowabe length of the input
- ' valid$ is a string containing all allowable characters
- ' sc% is the ascii code of the character used to fill in at the
- ' end of the input line.
-
- sp$ = " " 'blank space
- RR$ = "" 'existing response
- r1% = r%: c1% = c%
-
- ' Read RR$ from the screen for possible use if esc is pressed.
- FOR i% = 1 to nc%
- RR$ = RR$ + CHR$(SCREEN(r1%, c1%))
- c1% = c1% + 1
- IF c1% > 80 THEN c1% = c1% - 80: r1% = r1% + 1
- NEXT i%
-
- ' Establish row and column for maximum input length
- c1% = c1% - 1
- IF c1% < 1 THEN c1% = 80: r1% = r1% - 1
- rmax% = r1%: cmax% = c1%
-
- ' Add these codes to the list of those allowed for input
- enter$ = CHR$(13)
- rgt$ = CHR$(0)+CHR$(77)
- lft$ = CHR$(0)+CHR$(75)
- backsp$ = CHR$(8)
- insert$ = CHR$(0)+CHR$(82)
- delete$ = CHR$(0)+CHR$(83)
- esc$ = CHR$(27)
-
- test$ = valid$+enter$+backsp$+rgt$+lft$+insert$+delete$+esc$
-
- ' Begin the input routine
- done% = false%
- r1% = r%: c1% = c%
-
- WHILE NOT done%
- ky$ = ""
- keyent% = false%
-
- WHILE NOT keyent%
- CALL GETKBD(insert%,capslock%,numlock%,scrolllock%)
- IF insert% THEN
- LOCATE r1%, c1%, 1, 5, 8
- insflg% = true%
- ELSE
- LOCATE r1%, c1%, 1, 12
- insflg% = false%
- END IF
- CALL CLRKBD ' clear the keyboard buffer
-
- ' Get a single key entry from the keyboard
- B:
- ky$ = INKEY$
- IF LEN(ky$)=0 THEN GOTO B
- IF INSTR(test$,ky$) = 0 THEN GOTO B
- keyent% = true%
- IF ky$ = enter$ THEN
- ky$ = "enter"
- ELSEIF ky$ = backsp$ THEN ky$ = "backsp"
- ELSEIF ky$ = rgt$ THEN ky$ = "right"
- ELSEIF ky$ = lft$ THEN ky$ = "left"
- ELSEIF ky$ = insert$ THEN ky$ = "insert"
- ELSEIF ky$ = delete$ THEN ky$ = "delete"
- ELSEIF ky$ = esc$ THEN ky$ = "escape"
- END IF
- WEND
- SELECT CASE ky$
- CASE "enter"
- done% = true%
- CASE "backsp"
- CALL P(sp$,r1%,c1%,type%)
- GOSUB moveleft
- CASE "right"
- GOSUB moveright
- CASE "left"
- GOSUB moveleft
- CASE "insert"
- CASE "delete"
- moved% = false%
- WHILE NOT moved%
- r2% = rmax%: c2% = cmax%
- y$ = CHR$(sc%)
- WHILE NOT (r2% < r1%) AND NOT (c2% < c1%)
- x% = SCREEN(r2%,c2%): x$ = CHR$(x%)
- CALL P(y$,r2%,c2%,type%)
- y$ = x$
- c2% = c2% - 1
- IF c2% < 1 THEN c2% = 80 + c2%: r2% = r2% - 1
- WEND
- moved% = true%
- WEND
- CASE "escape"
- CALL P(RR$,r%,c%,type%)
- r1% = r%: c1% = c%
- CASE ELSE
- moved% = false%
- WHILE insflg% AND NOT moved%
- r2% = r1%: c2% = c1%
- y$ = " "
- WHILE NOT (r2% > rmax%) AND NOT (c2% > cmax%)
- x% = SCREEN(r2%,c2%): x$ = CHR$(x%)
- CALL P(y$,r2%,c2%,type%)
- y$ = x$
- c2% = c2% + 1
- IF c2% > 80 THEN c2% = c2% - 80: r2% = r2% + 1
- WEND
- moved% = true%
- WEND
- CALL P(ky$,r1%,c1%,type%)
- GOSUB moveright
- END SELECT
- WEND
- GOTO leaveinpt 'jump over the subroutines
-
- ' The following are subroutines used within the subprogram
- moveleft:
- IF NOT (r1% = r% AND c1% = c%) THEN
- IF c1% = 1 THEN
- c1% = 80: r1% = r1% - 1
- ELSE
- c1% = c1% - 1
- END IF
- ELSE BEEP
- END IF
- RETURN
- moveright:
- IF NOT (r1% = rmax% AND c1% = cmax%) THEN
- IF c1% = 80 THEN
- c1% = 1: r1% = r1% + 1
- ELSE
- c1% = c1% + 1
- END IF
- ELSE BEEP
- END IF
- RETURN
- leaveinpt:
- END SUB
-
-