Numeric field

mark mitchell cowhead at mac.com
Fri Oct 11 06:38:01 EDT 2002


Hi Jan,
Thanks for reiterating all the bases you're covering.  I thought it 
might be something like that.  It's amazing how difficult it is to 
develop for the 'widest' user-base, isn't it?  I did accomplish 
something similar to what you are doing using the starter-kit before 
though.  To restrict data input to a highly specific format, I usually 
use a special "data input field" and lock the display field (if there is 
one).  In other words, I check the input afterwards, to make sure the 
format is correct, prior to doing any calculations etc.  For example, 
the 5 script lines in this data-input field I think address all of the 
extra points you mentioned:

on returnInField

replace "," with "" in me
if me is a number then  -- bad English, even for a Texan
put return & me after field mDisplay  -- or perform any calculations here
else
answer "wrong format idiot"
end if
put "" into me -- or hide me or whatever

end returnInField

Of course, your script is much cooler and more complete and far more 
user-friendly, but the above will work pretty well for programmers with 
starter-kits or ADD (;-)

best,
mark

Jan wrote:

> The additional code covers several things:
>
> 1) if the user "pastes" data, you don't get a keydown
> -- so you need a special construction to handle the
> pasteKey (which, for additional fun, isn't sent when
> the RunRev UI is running).
>
> 2) if you want to enable the user to type a decimal
> number, you have to keep track of how many times he
> typed a period -- so you have to keep an eye on
> selections, and check if the new data after the
> keyDown would still be a number.
>
> 3) if the data must be displayed in a format with
> thousand separators or a comma instead of a point, you
> need functions to convert back and forth between
> display and calculation format.




More information about the Use-livecode mailing list