Limiting the number of characters per line in a scrolling field?
Cubist at aol.com
Cubist at aol.com
Sat Apr 23 15:07:51 EDT 2005
sez gbojsza at gmail.com:
>I would like to limit the number of characters a user can input on any
>line in a scrolling field.
>
>In the field script
>
>on keydown theKey
> if theKey is not in " 0 1 2 3 4 5 6 7 8 9 - . " then
> beep
> exit keydown
> else
> if (the length of me) > 4 then
> beep
> exit keydown
> end if
> pass keydown
> end if
>end keydown
>
> "if the length of me is > 4 then..." this works but limits the
>TOTAL field to 4 characters.
Well, you could always let the field be updated normally, and use "send
in" with a very short delay to check the field's contents *just* after that
update occurs. Like so...
local OldContents
on keyDown DisKey
put me into OldContents
if DisKey is in ".-1234567890" then
send "CheckMe" to me in 10 milliseconds
pass keyDown
else
beep
end if
end keyDown
on CheckMe
put the selectedChunk into Fred
# mind the e-mail line wrap here!
put the number of lines in (char 1 to (word 4 of the selectedChunk) of me
into DisLine
# and here, too!
if (line DisLine of me is not a number) or (the length of line DisLine of
me > 4) then
beep
put OldContents into me
end if
end CheckMe
Hmmm... "line DisLine of me is not a number" is supposed to cover all the
bases, numerical-input-wise, but if the user wants to type a negative number,
he'll start with a dash... not sure if "-" counts as a number... decimal
points could be bothersome in this respect, too... If need be, try this for the IF
statement instead:
if not (((line DisLine of me is a number) or (line DisLine of me is in ". -
-.")) and (the length of line DisLine of me <= 4)) then
Hope this helps...
More information about the use-livecode
mailing list