Constraining user input...

Sarah Reichelt sarahr at genesearch.com.au
Thu Feb 28 22:36:00 EST 2002


Greg,

The easiest way is to make two custom properties for each field you want to
constrain e.g.
    cMaxChars
    cMaxLines

After having done this, I then went on to test whether the script could be
put into the stack or card script and made totally general. It can, so put
this script in your stack script, then give the two new properties to any
field you want to constrain.

Along the way, the script got a lot better :-)

on keyDown theKey
  put the cMaxChars of the target into maxC
  put the cMaxLines of the target into maxL
  
  -- check to see if this object has the right properties
  -- if not, just pass the keyDown without checking constraints
  if maxL is empty or maxC is empty then pass keyDown
  
  -- if you are using the starter kit, the next three lines
  -- can be merged into one, it just looks messier.
  put word 2 of the selectedLine of the target into theLine
  put the value of the selectedLine of the target into theText
  if the length of theText >= maxC or theLine > maxL then
    beep
    exit keyDown
  else
    pass keyDown
  end if
end keyDown

Cheers,
Sarah

> Sarah, 
> 
> Thank you so much for the quick response....  This actually works quite well
> and is a great example, thank you!....  I do have one more question though,
> this is more out of curiosity I suppose...  Is there some way to store the
> "constraint" information as part of the field definition and make this a
> function which gets called?.. THe reason I ask is because I have to do this
> with about 150 different fields and it would get rather tedious to be cutting
> and pasting for each one of them.....
> 
> Again, thank you very much for your help -- I really *REALLY* appreciate
> it.... 
> 
> Greg Saylor 
> Senior Systems Integrator 




More information about the use-livecode mailing list