Sorting lines on colour (color for some)

J. Landman Gay jacque at hyperactivesw.com
Fri Sep 19 21:48:06 EDT 2014


On 9/19/2014, 8:18 PM, dunbarx at aol.com wrote:
> OK, I get that. But then how would a function, something you in
> particular are fond of, work?

In this case I wouldn't use any field access, it would be inefficient 
and slow for all but very short field contents. But if someone put a 
knife to my throat and said, "write a function or else," then I'd do it 
the same way Bernd did, only instead of counting lines in the 
styledText, I'd count lines in the field. It requires the engine to 
access the field repeatedly for every line and makes me wince:

local sCounter = 0

on mouseUp -- about to mangle Bernd's handler now
    put 0 into sCounter
    sort lines of field "fData" numeric ascending by myColor(each)
end mouseUp

function myColor
    add 1 to sCounter
    put the backcolor of line sCounter of fld "fData" into tRGB -- ow, ow

    if tRGB = "" then -- no backgroundColor
       return 0
    end if

    return item 1 of tRGB -- test for redness

    -- or do anything you want with R,G,B

end myColor

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com




More information about the use-livecode mailing list