home *** CD-ROM | disk | FTP | other *** search
- BASIC Screen Input Routines
-
- Ken Crebs
- Greater Cincinnati Ohio Users Group
-
- I have developed a generalized
- screen input subroutine in BASIC
- that I use extensively. Its
- capability to be customized makes it
- especially useful.
-
- The subroutine requires the
- following variables to be
- initialized:
-
- o the row and column where the
- input is to start.
- o the maximum length of the input.
- o the type of input.
- (Alphanumeric, Integer, or Real)
-
- The subroutine uses the INKEY$
- variable to examine each character
- as it is entered from the screen.
- The ASC function is used to validate
- each input character as it is stored
- in the variable INP.STR$. Numeric
- type data is converted using the VAL
- function. The left and right arrows
- on the numeric keypad are used to
- move the cursor within the field
- without affecting the contents.
- When the cursor goes beyond the
- specified maximum length, it is
- returned to the beginning of the
- field. The backspace key will erase
- the contents one character at a
- time.
-
- The subroutine returns the status of
- three different cases. The variable
- RTRN% is set to:
-
- 0 = Nothing was entered in the
- field, <Enter> was pressed.
- 1 = Normal operation, Data was
- entered and <Enter> was pressed.
- 9 = The <Esc> key was pressed.
- Usually means abort or start over.
-
- The subroutine GENIN is listed at
- lines 10000-10330. The
- demonstration program calls GENIN
- and displays the status of the call
- and the contents of the variable
- INP.STR$. When the program pauses
- (Break in 90), the values of KROW%,
- KCOL%, KLEN%, KTYP$, and KSIGN% can
- be changed and the CONT command used
- to resume execution.
-
- The subroutine will handle most
- screen input situations, but it can
- also be modified for special cases
- fairly easily.
-
- Here are a few special cases and the
- suggested modifications:
-
-
- 1. Recognition of special keys
- being pressed: <Ins>, <Del>,
- <F1>, <F2>, etc. The ASCII
- codes for these keys can be
- found on page G-7 in the
- appendix of the BASIC Reference
- Manual. For example, to
- recognize the function key <F1>,
- I would add the line:
-
- 10115 IF CS$=CHR$(0)+CHR$(59)
- THEN LOCATE ,,0:RTRN%=2:RETURN
- '<F1>
-
- The calling program would then
- check for a RTRN% value of 2 and
- take the appropriate action.
-
- * Note: The <F1> function key
- must be disabled first. I
- usually disable all the function
- keys at the beginning of my
- program like this:
-
- KEY OFF:FOR I%=1 TO 10:KEY
- I%,"":NEXT
-
- 2. Recognition of a specific input
- or a range of inputs. Use the
- variable KTYP$ to define a new
- data type. For example, to
- recognize only the input of a
- "Y" or and "N", I would define a
- new data type, say KTYP$="q".
- Then add the line:
-
- 10165 IF KTYP$="q" THEN IF
- (ACODE%<>89 AND ACODE%<>121 AND
- ACODE%<>78 AND ACODE%<>110) THEN
- BEEP:GOTO 10080 ELSE GOTO 10200
-
- * Note: In the demonstration
- program set KLEN%=1 AND
- KTYP$="Q".
-
- 3. Audible recognition when the end
- of the input field is reached.
- Remove the comment on line 10060
- and the subroutine will sound a
- low beep when the cursor has
- gone past the end of the input
- field.
-
- 4. Automatic conversion of
- lowercase characters to
- uppercase. Add the line:
-
- 10195 IF ACODE%>96 THEN
- CS$=CHR$(ACODE%-32)
-
- If you want to input multiple
- fields, use a loop to make repeated
- calls to GENIN with each field's
- attributes stored in arrays. I
- think you can see the versatility of
- having the screen input function in
- one place. I hope this subroutine
- will be as useful to you as it is to
- me.
-
- [ Editor's Note: The program is
- rather lengthy so the source is not
- listed here. However, the source
- exists as a separate file on this
- newsletter diskette and may be
- copied to your work diskette. The
- source file name is: SCREEN.BAS ]