Page 1 of 1

limit a text filed to the first 3 lines

Posted: Mon Jan 18, 2016 9:53 am
by link76
Hello,

I want to limit a text filed to the first 3 lines

Code: Select all

on keyDown thePressedKey

   if the number of lines of me  ....   

end keyDown
thank you,

Re: limit a text filed to the first 3 lines

Posted: Mon Jan 18, 2016 11:24 am
by Klaus
Hi link7,

maybe something like this:

Code: Select all

on returninfield
   if the num of lines of me < 3 then
      pass returninfield
   end if
end returninfield

on enterinfield
     if the num of lines of me < 3 then
      pass enterinfield
   end if
end enterinfield
Tested and works!


Best

Klaus

Re: limit a text filed to the first 3 lines

Posted: Mon Jan 18, 2016 11:29 am
by AndyP
or a slight variation

Code: Select all

on returninField
   if word 2 of the selectedLine of me >=3 then
      put line 1 to 3 of me into me
   else
      pass returninField
   end if
end returninField

Re: limit a text filed to the first 3 lines

Posted: Mon Jan 18, 2016 11:36 am
by FredBeck
Hi!
You're all assuming the don'tWrap property of the field is true!

Code: Select all

on keyDown
   if TypingAllowed() then
      pass keyDown
   end if
end keyDown

on rawKeyUp
   if not TypingAllowed() then
      repeat until TypingAllowed()
         delete last char of me
      end repeat
   end if
   pass rawKeyUp
end rawKeyUp

on returnInField
   if TypingAllowed() then pass returnInField
end returnInField

on enterInField
      if TypingAllowed() then pass enterInField
end enterInField

-----------------------------------------------------------

function TypingAllowed
   if the dontWrap of me then
      if the number lines in me < 4 then
         return true 
      end if
   else
      if the numberOfWrappedLines of me < 4 then
         return true 
      end if
   end if
   return false
end TypingAllowed

------------------------------------------------------------

getProp numberOfWrappedLines
   put the textHeightSum of me into tTextHeightSum
   if the fixedLineHeight of me then
      put the effective textHeight of me into tLineHeight
   else
      put the effective textSize of me into tLineHeight
   end if
   get tTextHeightSum / tLineHeight
   return it
end numberOfWrappedLines

Re: limit a text filed to the first 3 lines

Posted: Mon Jan 18, 2016 11:42 am
by Klaus
Hi Fred,
FredBeck wrote:You're all assuming the don'tWrap property of the field is true!
...
yes, we are just lazy! 8)


Best

Klaus

Re: limit a text filed to the first 3 lines

Posted: Mon Jan 18, 2016 12:24 pm
by AndyP
Hmm.. I always assume things to be true ... unless proven false?

Re: limit a text filed to the first 3 lines

Posted: Mon Jan 18, 2016 2:29 pm
by FredBeck
Winter Monday morning deep in german continental climate... I feel for you, you're forgiven :mrgreen:

Re: limit a text filed to the first 3 lines

Posted: Mon Jan 18, 2016 3:04 pm
by Klaus
Thank you, sir!

To my excuse, we are currently moving and are living out of boxes in the moment,
so many shelves, screws and nails to remove, so many things to put into these namely boxes...

I HATE IT! :D

Re: limit a text filed to the first 3 lines

Posted: Mon Jan 18, 2016 10:42 pm
by jacque
This may be a little easier:

Code: Select all

on keydown
  put (item 2 of the selectedloc of me + the vscroll of me) div (the effective textheight of me) into tLine
  if tLine < 3 then  pass keydown
end keydown