home *** CD-ROM | disk | FTP | other *** search
-
- SUB keyboard (instring$, length%, number%, insert%, outstring$)
- 'instring$ is a string passed to the routine
- 'length% is the length of the string you want
- 'number% sets input for numeric only (1) or alpha (0)
- 'insert% sets insert mode (1) or overwrite (0)
- 'outstring$ is the string returned to your program
- IF instring$ = "" THEN
- b$ = SPACE$(length%) 'if no existing string, then new string
- ELSE
- pad% = length% - LEN(instring$)
- b$ = instring$ + SPACE$(pad%) 'edit existing string
- END IF
- beginline% = POS(s)
- hlocation% = POS(s) 'location of cursor on line
- digit$ = "-.0123456789"
- current% = 1 'location of character in string
- DO
- DO
- LOCATE , hlocation%, 1 'position cursor and turn it on
- a$ = INKEY$ 'get a character from keyboard
- LOOP WHILE a$ = ""
- a% = ASC(RIGHT$(a$, 1)) 'extract key code
- SELECT CASE a% 'determine what to do
- CASE 13 'if ENTER
- outstring$ = RTRIM$(b$) 'assign outstring its value minus spaces
- EXIT SUB 'quit
- CASE 75 'left arrow
- hlocation% = hlocation% - 1 'reset location on line
- current% = current% - 1 'move back current character
- LOCATE , hlocation% 'move back on line
- CASE 77 'right arrow
- LOCATE , hlocation% + 1 'move cursor
- current% = current% + 1 'update position in string
- hlocation% = hlocation% + 1 'update position on line
- CASE 72 'up arrow
- length% = 0 'tells calling prog what follows isn't a string
- outstring$ = "UP" 'lets calling prog know what happened
- EXIT SUB
- CASE 80
- length% = 0 'same as above but down arrow
- outstring$ = "DN"
- EXIT SUB
- CASE 71 'home key is pressed
- LOCATE , beginline% 'go to beginning of field
- hlocation% = beginline% 'update position on line
- current% = 1 'update position in string
- CASE 79 'end key is pressed
- LOCATE , beginline% + length% 'go to end of field
- hlocation% = beginline% + length% - 1 'update position on line
- current% = length% - 1 'update position in string
- CASE 83 'delete key is pressed
- FOR x% = current% TO length% - 1 'move all the other
- MID$(b$, x%, 1) = MID$(b$, x% + 1, 1) ' characters left one
- PRINT MID$(b$, x% + 1, 1); ' space
- NEXT x%
- MID$(b$, length%, 1) = " " 'the last character in field is a space
- LOCATE , beginline% + length% - 1 'move cursor
- PRINT " "; 'erase character
- LOCATE , hlocation% 'reset cursor
- CASE 8 'backspace is pressed
- IF current% = length% THEN 'cursor at end of field
- LOCATE , hlocation% 'move cursor
- PRINT " "; 'erase character
- hlocation% = hlocation% - 1 'update position on line
- current% = current% - 1 'update position in string
- MID$(b$, length%, 1) = " " 'last character in field is a space
- LOCATE , hlocation% 'move cursor
- ELSE
- IF current% > 1 THEN 'cursor is in field
- FOR x% = current% TO length% - 1 'move all the other
- MID$(b$, x%, 1) = MID$(b$, x% + 1, 1) ' characters left one
- PRINT MID$(b$, x%, 1); ' space
- NEXT x%
- MID$(b$, length%, 1) = " " 'last character is a space
- LOCATE , beginline% + length% - 1 'move cursor
- PRINT " "; 'erase character
- hlocation% = hlocation% - 1 'update location on line
- current% = current% - 1 'update position in string
- LOCATE , hlocation% 'move cursor
- END IF
- END IF
- CASE ELSE
- IF number% AND current% <= length% THEN 'if only numeric input
- IF INSTR(digit$, a$) THEN 'check to see if character is allowed
- MID$(b$, current%, 1) = a$ 'set proper character
- PRINT a$; 'print the character
- IF current% < length% THEN
- current% = current% + 1 'update position in string
- hlocation% = hlocation% + 1 'update line position
- END IF
- ELSE
- BEEP 'not a digit, say so
- END IF
- ELSEIF current% <= length% THEN 'other characters allowed
- IF insert% THEN 'is insert mode on
- FOR x% = length% TO current% + 1 STEP -1
- MID$(b$, x%, 1) = MID$(b$, x% - 1, 1) 'push characters right
- LOCATE , beginline% + (x% - 1), 0 'move cursor, set cursor off
- PRINT MID$(b$, x%, 1); 'print moved characters
- NEXT x%
- END IF
- LOCATE , hlocation%, 1 'update position on line
- MID$(b$, current%, 1) = a$ 'set proper character
- PRINT a$; 'print the character
- IF current% < length% THEN 'check if we're past end of field
- current% = current% + 1 'update position in string
- hlocation% = hlocation% + 1 'update position on line
- END IF
- ELSE
- BEEP 'max number of characters, say so
- END IF
- END SELECT
- LOOP
- END SUB
-
-