KEYBOARD
Control keyboard input
Are you looking for something like this?
WINDOW 1
"begin"
INPUT a$
bad = 0
FOR X = 1 TO LEN(a$)
LONG IF ASC(MID$(a$,X)) < 48 OR ASC(MID$(a$,X)) > 59
bad = 1
X = LEN(a$)
END IF
NEXT X
IF bad = 1 THEN BEEP : GOTO "begin"
num = VAL(a$)
PRINT num
DELAY 1000
END
What I've done in the past is to setup a field and assign it a class (which has to be a multiple of 4). Then I use ON EDIT to check the key input using TEKEY$. Something like this (quick & dirty)
CLEAR LOCAL
LOCAL FN checkInput
goodInput = _true
fldClass = WINDOW (_efClass)
char$ = TEKEY$
SELECT fldClass
CASE _numericOnly
charVal = ASC(char$)
LONG IF charVal < _"0" OR charVal > "9"
LONG IF charVal <> _"."
goodInput% = _false
END IF
END IF
CASE _stringClass
'check for valid character input
CASE ELSE
END SELECT
LONG IF goodInput = _true
TEKEY$ = char$
XELSE
BEEP 'give user some type of error response
END IF
END FN
ON EDIT FN checkInput
_numericOnly = 1 << 2
_stringClass = 2 << 2
EDIT FIELD 1,"",(left,top) - (right,bottom), _framed + _numericOnly
LOCAL
'//
'// Inputs a string and returns _true if string is numeric
'//
LOCAL FN IsNumeric%(a$)
DIM n%, L%
DIM i
DIM 1 c$
L% = LEN(a$)
LONG IF L% > 0
i = 0 : n% = _true
DO
INC(i) : c$ = MID$(a$,i,1)
LONG IF c$ < "E"
LONG IF c$ > "9"
n% = _false
XELSE
LONG IF c$ < " "
n% = _false
XELSE
LONG IF (c$ > " ") AND (c$ < "+")
n% = _false
XELSE
IF (c$ = ",") OR (c$ = "/") THEN n% = _false
END IF
END IF
END IF
XELSE
REM e or E may be included in scientific number format
n% = _false : IF (c$ = "E") OR (c$ = "e") THEN n% = _true
END IF
UNTIL i=L% OR n% = _false
XELSE
n% = _false
END IF
END FN = n%
|