keyInField

Jan Schenkel janschenkel at yahoo.com
Thu Sep 26 07:55:00 EDT 2002


Hi Bob,

I was going to save this for a stack of template
fields, but here it goes:

--- 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) & pWhickKey \
    into tCheck
    if length(me) > theStart then
      put (char tStart to -1 of me) after tCheck
    end if
  else
    put (char 1 to tStart - 1 of me) & pWhickKey \
    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

---

Hope this helped,

Jan Schenkel.

"As we grow older, we grow both wiser and more foolish
at the same time."  (De Rochefoucald)

--- Robert Presender <rpresender at earthlink.net> wrote:
> Appreciate any  suggestions that would replace the
> following script, 
> that I used in SuperCard, to one in Revolution. 
> Want to enter only 
> certain chars into a field.
> 
> on openField
>    set the numberFormat to "0.000"
>    keyInField theKey
>    add 0 to me
> end openField
> 
> on keyInField theKey
>    set allowKeyInField to true
>    if theKey is in "0123456789." or
> charToNum(theKey) = 8 then pass 
> keyInField
> end keyInField
> 
> Regards ... Bob
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
>
http://lists.runrev.com/mailman/listinfo/use-revolution


__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com



More information about the use-livecode mailing list