home *** CD-ROM | disk | FTP | other *** search
- 'QBINPUT.SUB - subroutine to build input string in a controlled manner
- 'written by l.m. bernbaum
- 'Copyright LMB Enterprises, 1986
- 'No Charge - use it as you see fit
- '
- '
- 'Either merge this code into your Quikbasic program directly, or remember to
- 'include it via the QB Metacommand REM $INCLUDE: 'QBINPUT.SUB'.
- '
- 'You call this routine from within a program with the command:
- '
- 'CALL GETINP(IX,IY,MAXLEN,FILL,GETKEY$,WRAP)
- '
- 'where IX = The line number (between 1 and 23)
- ' IY = The column number (between 1 and (79-MAXLEN))
- ' MAXLEN = The desired length of the string
- ' FILL = The ASCII decimal value of the desired filler in the
- ' input area. Example ASCII 42 = *, thus a FILL of 42
- ' would create an input area filled with asteriks to
- ' show the user the field length.
- ' GETKEY$ = The input string returned to the calling program
- ' WRAP = 1=enable wrapping;anything else reuires a CR to end input
- '
- SUB GETINP(ix,iy,maxlen,fill,getkey$,wrap) STATIC
- '
- 'make sure input string\work string empty
- getkey$="":del$=""
- '
- 'locate and print input area with prespecified "filler string"(FILL)
- 'at specified input location
- locate ix,iy:print string$(maxlen,fill):locate ix,iy,1
- '
- 'loop for required number of characters - set by MAXLEN
- inloop: while len(getkey$)<=maxlen-1
- char$=""
- while char$="" 'wait for a char
- char$=inkey$ 'to be entered
- wend
- if asc(char$)=13 then 'CR terminates
- locate ,,0 'turn off cursor
- goto don 'get out of loop
- '
- 'screen bad chars first
- '
- elseif asc(char$)<=7 or asc(char$)>=10 and asc(char$)<=12 or_
- asc(char$)>=14 and asc(char$)<=31 or asc(char$)>=127 then
- locate ix,iy,0:print getkey$ 'ignore key
- locate ix,(iy+(int(len(getkey$)))),1 'reset cursor
- '
- 'process a backspace key
- '
- elseif asc(char$)=8 and len(getkey$)>=1 then 'backspace
- del$=left$(getkey$,(len(getkey$)-1)) 'delete a char
- getkey$=del$ 'from work string
- locate ix,iy,0:print getkey$ 'print the new
- locate ix,(iy+(int(len(getkey$)))) 'string and then
- print string$((maxlen-len(getkey$)),fill) 'new input filler
- locate ix,(iy+(int(len(getkey$)))),1 'reset cursor pos
- '
- 'ignore tab key
- '
- elseif asc(char$)=9 then 'beep on tab
- locate ix,iy,0:print getkey$;chr$(7) 'key;ignore tab
- locate ix,(iy+(int(len(getkey$)))),1 'reset cursor
- '
- ' at last an acceptable character
- '
- else getkey$=getkey$+char$ 'accept input
- locate ix,iy,0:print getkey$ 'character and
- locate ix,(iy+(int(len(getkey$)))),1 'add to string
- end if
- wend 'loop until maxlen reached or c/r issued
- getret: if wrap=1 then 'wrap around
- goto don 'enabled = 1
- end if
- char$="" 'on wrap around
- while char$="" 'don't wait for
- char$=inkey$ 'return key.
- wend
- if asc(char$)=8 and len(getkey$)=maxlen then 'in non-wrap mode
- del$=left$(getkey$,(len(getkey$)-1)) 'check for a
- getkey$=del$ 'backspace before
- locate ix,iy,0:print getkey$ 'CR;delete last
- locate ix,(iy+(int(len(getkey$)))) 'char, print new
- print string$((maxlen-len(getkey$)),fill) 'input string
- locate ix,(iy+(int(len(getkey$)))),1 'pad filler,locate
- goto inloop 'cursor and go back
- end if 'to input loop.
- if asc(char$)<>13 then
- char$=""
- goto getret
- else
- goto don
- end if
- don: 'exit point for subroutine
- wrap=0 'disable wrap unless asked for specifically by each subprog call
- EXIT SUB
- END SUB