How to test for a number

Klaus Major klaus at major-k.de
Wed Mar 16 10:59:41 EST 2005


Hi Jonathan,

> I have a field where I restrict it to only enter numbers...
>
> But I had to include extra script to allow the character to be a "." 
> or a "-", in case the number included a decimal point or minus sign:
>
> On KeyDown theKey
>      If (isNumber(theKey) = true) or theKey = "." or theKey = "-" then 
> pass keyDown
> End KeyDown

ah, yes, sure...

But we non english speaking users do have another problem!

We use the "," (Comma) as a decimal separator, so we have to do some 
extra
work before we can compute some values... :-(

If somone is interested, i use these 2 little functions to do the 
conversations before
computing and displaying the result again:

function ohnekomma was
## german for without comma :-)
    replace "," with "." in was
    return was
end ohnekomma

And back:

function mitkomma was
## german for with comma :-)
    replace "." with "," in was
    return was
end ohnekomma

So i can:
...
put mitkomma((ohnekomma(fld 1) * 12)) into fld "result"
...


Or a bit more readable ;-)
...
put ohnekomma(fld 1) into mynumber1
put mynumber * 12 into myresult
put mitkomma(myresult) into fld "result"
...


Regards

Klaus Major
klaus at major-k.de
http://www.major-k.de



More information about the use-livecode mailing list