keyInField
Jan Schenkel
janschenkel at yahoo.com
Thu Sep 26 08:01:01 EDT 2002
Sorry Bob,
I only noticed the typos in the script after I got it
back in my inbox. Here it goes again...
--- Field script for a numeric field
local sBeforePaste
on keyDown pWhichKey
put the selectedChunk into tChunk
put word 2 of tChunk into tStart
put word 4 of tChunk into tStop
if tStart > tStop -- no actual selection
put (char 1 to tStop of me) & pWhichKey \
into tCheck
if length(me) > theStart then
put (char tStart to -1 of me) after tCheck
end if
else -- typing would replace the selected text
put (char 1 to tStart - 1 of me) & pWhichKey \
into tCheck
if length(me) > theStop then
put (char tStop + 1 to -1 of me) after tCheck
end if
end if
if tCheck is a number then pass keyDown
else beep
end keyDown
-- Reformat upon leaving the field
on closeField
send "formatField" to me in 5 milliseconds
end closeField
on formatField
put (me) into tNumber
put format("%16.3f", tNumber) into tFormatted
repeat while char 1 of tFormatted = " "
delete char 1 of tFormatted
end repeat
put tFormatted into me
end formatField
-- Handle pasting of text in this field
-- NOTE : doesn't work when Rev UI is ON
on pasteKey
put (me) into sBeforePaste
send "checkAfterPaste" to me in 5 milliseconds
pass pasteKey
end pasteKey
on checkAfterPaste
put (me) into tAfterPaste
if tAfterPaste is not a number then
beep
put sBeforePaste into me
end if
end checkAfterPaste
---
My apologies,
Jan Schenkel.
"As we grow older, we grow both wiser and more foolish
at the same time." (De Rochefoucald)
__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com
More information about the use-livecode
mailing list