How to test for a number

Kevin J kj2005.28 at gmail.com
Wed Mar 16 11:04:16 EST 2005


I like that idea of:

on keydown tKey
  if tKey is a number then
     pass keydown
  else
    beep
  end if
end keydown

Is it ok to put it in the main stack rather then puting it just for
the fields. I did it and it seems to work fine. Plus when ever you
don't put anything in the field you will still get the normal warrning
that you need to put a number in it. I have included a standalone and
the source if anyone would like to look at it. This is the first
program I have finished it might be small and simple but it works lol.

http://www.lotheria.com/Simplecalc.zip

On Wed, 16 Mar 2005 10:42:27 -0500, Lynch, Jonathan <BNZ2 at cdc.gov> wrote:
> 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
> 
> 
> -----Original Message-----
> From: use-revolution-bounces at lists.runrev.com [mailto:use-revolution-bounces at lists.runrev.com] On Behalf Of Klaus Major
> Sent: Wednesday, March 16, 2005 10:37 AM
> To: Kevin J; How to use Revolution
> Subject: Re: How to test for a number
> 
> Hi Kevin,
> 
> > How do you make an If check to check to see if a user has entered a
> > number and not a letter?
> > I can stop it from doing a divide by 0 doing this:
> >
> > on mouseUp
> > put field"num1" into tAdd
> > put field"num2" into tAdd2
> >   if tAdd2 is 0 then
> >     answer "You can't divide by 0"
> >   else
> >     put tAdd/tAdd2 into field"sum"
> >     end if
> > end mouseUp
> 
> well, check "if add2 is a number" :-)
> 
> on mouseUp
>     put field"num1" into tAdd
>     put field"num2" into tAdd2
>     if tAdd2 is 0 then
>        answer "You can't divide by 0"
>        exit mouseup
>     end if
>     if tAdd2 is a number then
>        put tAdd/tAdd2 into field"sum"
>     else
>        answer "*##+[¢]|≠¿¿"
>        ## Or something more meaningful :-)
>     end if
> end mouseUp
> 
> But you can also restrict your field to only allow numbers!
> 
> Put this into the script of your field:
> 
> on keydown tKey
>    if tKey is a number then
>       pass keydown
>    else
>      beep
>    end if
> end keydown
> 
> This way only numbers can be entered into that field...
> 
> Hope that helps.
> 
> > Thanks
> >
> > Kevin
> 
> Regards
> 
> Klaus Major
> klaus at major-k.de
> http://www.major-k.de
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 
> 
>


More information about the use-livecode mailing list