Re: How to enter a floating-point number ?



David Necas (Yeti) wrote:
On Sat, May 29, 2004 at 09:40:47PM +1000, Russell Shaw wrote:

This is a parser problem. Every time a key is pressed, the callback
advances thru your implementation of a floating-point number parser.
When an invalid character is pressed, your callback can simply refuse
to accept the character, make a beep, and display an error message in
the status line. The parser is not hard (only 100 lines of code as
a switch-statement state machine).

IMHO this is a logical problem.

If you allow only things that correctly parse as floating
point numbers, the user will have hard time editing the
numbers, because after each key press the number has to be
parseable.  This is very annoying, especially for numbers
with an exponent.

But if you allow any transitional states, you'll lose you
point because there will be non-number things that can be
entered then, so you'll have to handle them anyway.

The parsers i've done go forwards and backwards, so you can
use the backspace key. If you change a character midway in the
number, the parser just rescans the entire string (as it does
for all keypresses) and allows or disallows that change,
because it remembers the previous entry.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]