newbie question (text wrap)

José L. Rodríguez Illera jlrodrig at ariadna.d5.ub.es
Tue Jan 28 16:44:01 EST 2003


> 
> A newbie question:
> 
> I want to wrap some single line text in a text box and not use a
> horizontal scroll bar.  I have an algorithm that works.
> 
> But it is horribly inefficient and I'm sure there must be a better way!
> Can you X-talk gurus help me out with this one?
> 
> if (the length of this_line > 80) then
> repeat with i = 1 to the length of this_line
>   put char i of this_line after field "contents"
>   if (i mod 80 = 0) then put return after field "contents"
> end repeat
> end if
> 
> Mahalo!
Hi Sadhu,

I understand you want to pad the text  to a fixed lenght (in fld 1 or in a
variable) to a fld 2. Try this:

local thetext, counterr, tam
on mouseup
  put 0 into counterr
  put 80 into tam

  repeat for each char x in fld 1
    add 1 to counterr
    if x=cr then  ---you have to control if the char is a return
      put cr after thetext
      put 0 into counterr
    else
      put x after thetext
    end if

    if counterr=tam then
      put 0 into counterr
      put cr after thetext
    end if
  end repeat

  put thetext into fld 2
end mouseup

Sure the script may be tunned, but even in this form it is very fast for
small texts (some thousands of chars).

Regards,

Jose L. Rodriguez





More information about the metacard mailing list