How to test for a number

Ken Ray kray at sonsothunder.com
Wed Mar 16 19:13:29 EST 2005


On 3/16/05 3:44 PM, "Cubist at aol.com" <Cubist at aol.com> wrote:

> sez kj2005.28 at gmail.com:
>> 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.
>    That depends on what you want the user to be able to do with the stack.
> Put that handler in the main stack script, and the user can NEVER type a
> non-numeral character into ANY field in that stack. Is that what you want? If
> you 
> want *some* fields to be number-restricted, while others are normal, you could
> put that handler into the script of the appropriate card(s). If the
> number-restricted fields are all part of the same group, you can put that
> handler into the 
> script of that group, and it will affect only the fields you want, while
> leaving everything else alone.

Better yet would be to assign a user property to those fields (like
"uNumbersOnly"), give it a value (like "true") and then check it in the
keydown handler, like:

on keydown tKey
  if the uNumbersOnly of the target = "true" then
    if tKey is a number then
      pass keydown
    else
     beep
    end if
  else
    pass keydown
  end if
end keydown

HTH,

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the Use-livecode mailing list