Faster way to get tabStops?

Mike Bonner bonnmike at gmail.com
Wed Feb 18 19:48:48 EST 2015


Or what mark S said, though if you have styled text, the number of chars in
the line <> the formattedwidth, so that may not work, but neither will
mine.  SO yep, interesting problem.
Ah. Got it.

If the "last line" of text is a fast chunk (or the first for that matter)
you can set the htmltext of a hidden field to the htmltext of the field
you're working with then..
repeat until field whatever is empty
repeat with i = 1 to the number of items in the last line of field...
Check the width of each item of the line as you do above. (this can be the
first line too if that works for you)
then "delete the last line of field..."
end repeat
end repeat

Using this method you avoid the whole "counting up through the lines of the
field.." issue, and still end up with valid data.

On Wed, Feb 18, 2015 at 5:40 PM, Mark Schonewille <
m.schonewille at economy-x-talk.com> wrote:

> Hi Dan,
>
> Don't use repeat loops. Just sort the lines by the number of chars of item
> x and get the lineoffset for that line. When you know the line number, you
> can get the formattedWidth of the longest item in that line and base the
> tabstops on that.
>
> If you use a clever function, you should also be able to sort lines
> directly by the formattedWidth of their respective items, but that might be
> a little slow again.
>
> --
> Best regards,
>
> Mark Schonewille
>
> Economy-x-Talk Consulting and Software Engineering
> Homepage: http://economy-x-talk.com
> Twitter: http://twitter.com/xtalkprogrammer
> KvK: 50277553
>
> Installer Maker for LiveCode:
> http://qery.us/468
>
> Buy my new book "Programming LiveCode for the Real Beginner"
> http://qery.us/3fi
>
> LiveCode on Facebook:
> https://www.facebook.com/groups/runrev/
>
>
> On 2/19/2015 00:50, Dan Friedman wrote:
>
>> Greetings!  I am trying to set the tabStops to fit the data a field.  The
>> script below works great!  However, ask it to process a few thousand lines
>> with 10 or so columns, and you'll have time to get a cup of coffee!  Any
>> ideas on how to speed this up?  Maybe there is some magical property I
>> don't about?
>>
>> Thanks in advance,
>> -Dan
>>
>>
>> on formatData
>>    set the itemDel to tab
>>    put "" into theTabs
>>
>>    put 0 into l
>>    repeat for each line tLine in fld "myField"
>>      add 1 to l
>>      put 0 into i
>>      repeat for each item tItem in tLine
>>        add 1 to i
>>        if the formattedWidth of item i of line l of fld "myField" > item
>> i of theTabs then
>>          put the formattedWidth of item i of line l of fld "myField" into
>> item i of theTabs
>>        end if
>>      end repeat
>>    end repeat
>>
>>    put "" into fTabs
>>    put 0 into i
>>    put 0 into tTotal
>>    repeat for each item tItem in theTabs
>>      add 1 to i
>>      add tItem+20 to tTotal
>>      put tTotal into item i of fTabs
>>    end repeat
>>
>>    replace tab with "," in fTabs
>>
>>    set the tabStops of fld "myField" to fTabs
>> end formatData
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list