Chip,
You're almost there but, to be thorough, the fn shouldn't let you
type numbers in front of the sign. (Try this: Type "-123"; cursor up;
"999")
Here is yet another version that is a few lines shorter and handles that case.
LOCAL FN numericFilter
DIM AS STR15 k
DIM AS STR255 cStr
DIM AS LONG id, p, n, pass
k = TEKEY$
id = WINDOW(_efNum)
cStr = EDIT$(id)
n = INSTR(1, cStr, "-")
pass = (WINDOW(_selEnd) >= n)
SELECT ASC(k)
CASE 8, 28, 29, 30, 31, 127 : pass = _zTrue
CASE > ASC("9") : pass = _False
CASE >= ASC("0")
CASE ASC(".")
p = INSTR(1, cStr, ".")
LONG IF p
IF WINDOW( _selEnd ) <= p THEN pass = _False
IF WINDOW(_selStart) >= p THEN pass = _False
END IF
CASE ASC("-")
IF WINDOW(_selStart) THEN pass = _False
CASE ELSE : pass = _False
END SELECT
IF pass THEN TEKEY$ = k
END FN
Otherwise, looking good--should go into the Rosetta file or some such
archive. One question though--Why do you want to make constant calls
to the ASC("X") fn rather than use the literal form (_"X")? I think
the literal makes the code easier to read, and I'm sure it compiles
smaller and runs faster.
e-e
=J= a y
"
>Here is an updated, and more elegant, numeric filter solution.
>Thanks to the more recent suggestions, this one reacts better to "."
>and "-" when typing with selected text. This was an EXCELLENT
>learning experience. Thanks a ton to all who contributed. This
>little snippet is going in the SAVE FOR FREQUENT USE bin.
>
>
>[extra spaces added here for easier reading]
>
>LOCAL FN numericFilter
> DIM AS STR15 k
> DIM AS STR255 cStr
> DIM AS LONG id, p, n
> DIM AS BOOLEAN pass
>
> k = TEKEY$
> id = WINDOW(_efNum)
> cStr = EDIT$(id)
> n = INSTR(1, cStr, "-")
> pass = _True
>
> SELECT ASC(k)
> CASE 8, 28, 29, 30, 31, 127
> CASE > ASC("9") : pass = _False
> CASE >= ASC("0")
> CASE ASC(".")
> IF WINDOW( _selEnd ) < n THEN pass = _False
> p = INSTR(1, cStr, ".")
> LONG IF p
> IF WINDOW( _selEnd ) <= p THEN pass = _False
> IF WINDOW(_selStart) >= p THEN pass = _False
> END IF
> CASE ASC("-")
> IF WINDOW(_selStart) THEN pass = _False
> IF window( _selEnd ) < n THEN pass = _False
> CASE ELSE : pass = _False
> END SELECT
> IF pass THEN TEKEY$ = k
>END FN
>
>--
>-- Chip <mailto:n1mie@...>
>
>--
>To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>