Limiting data entry in fields
Monte Goulding
monte at sweattechnologies.com
Mon Nov 29 19:37:01 EST 2010
Hi Charles
I'm a little confused about your requirements. Did you want to allow decimals or not? Here's some code copied from one of my behavior scripts. You only need to modify the one function to impose whatever data entry limits you like:
on keydown pKey
if checkText(getNewText(pKey)) then
setNewText pKey
else
beep 1
end if
end keyDown
on pasteKey
if checkText(getNewText(the clipboardData["text"])) then
paste
else
beep 1
end if
end pasteKey
# This is the only function you need to change to vary the acceptable data entry
private function checkText pText
return pText is an integer
end checkText
private function getNewText pNewChars
local tEndChar,tStartChar,tText
put word 2 of the selectedchunk of me into tStartChar
put word 4 of the selectedchunk of me into tEndChar
put the text of me into tText
put pNewChars into char tStartChar to tEndChar of tText
return tText
end getNewText
private command setNewText pNewChars
local tEndChar,tStartChar,tText
put word 2 of the selectedchunk of me into tStartChar
put word 4 of the selectedchunk of me into tEndChar
put pNewChars into char tStartChar to tEndChar of me
end setNewText
Cheers
Monte
More information about the use-livecode
mailing list