Custom property & selection of text

Rob Cozens rcozens at pon.net
Thu Jul 8 19:58:36 EDT 2004


>I have a stack with a field that contains a line of text. I want to
>programmatically select (hilite) a portion of the text. If I use something
>like:
>
>select word 1 to 4 of field 1
>wait 2 seconds
>
>...that works fine. However, each card on which the field appears will have
>a different sentence with varying qtys of words. The content will be static.
>I'd like to utilize some custom properties in each field to keep track of
>which groups of words are to be hilited. I was thinking of something like
>this (for one of the fields):
>
>Custom peoperty     holding
>sec1                "word 1 to 4"
>sec2                "word 5 to 8"
>
>(note that another card's field might have three custom properties of "word
>1 to 4", "word 5 to 7", and "word 8 to 12")
>
>...but the scripting of this escapes me.

Hi Barry,

Create a custom property, eg: words2Select, and set each field's 
words2Select as appropriate.  In your example, 'set the words2Select 
of field 1 to "1,4"&return&"5,8"'; 'set the words2Select of field 1 
to "1,4"&return&"5,7"&return&"8,12"'.

Your handler might look something like this:

on openCard
    get the words2Select of field 1 -- Note this assumes field 1 is 
not a background grouped control
    repeat for each line newSelection in it
       select word (item 1 of newSelection) to word (item 2 of 
newSelection) of field 1
       wait 2 seconds
    end repeat
    select empty
end openCard

As alternatives, one can:

on openCard
    get the words2Select of field 1
    repeat for each line newSelection in it
       set the textStyle of word (item 1 of newSelection) to word 
(item 2 of newSelection) of field 1 to bold
       wait 2 seconds
       set the textStyle of word (item 1 of newSelection) to word 
(item 2 of newSelection) of field 1 to empty
    end repeat
end openCard

or

on openCard
    get the words2Select of field 1
    repeat for each line newSelection in it
       set the textColor of word (item 1 of newSelection) to word 
(item 2 of newSelection) of field 1 to [the color or your choice]
       wait 2 seconds
       set the textColor of word (item 1 of newSelection) to word 
(item 2 of newSelection) of field 1 to empty
    end repeat
end openCard

-- 

Rob Cozens
CCW, Serendipity Software Company

"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."

from "The Triple Foole" by John Donne (1572-1631)


More information about the use-livecode mailing list