text color
Mike Bonner
bonnmike at gmail.com
Tue Nov 22 12:33:39 EST 2011
Oops, me again. If you want to change the color of text anywhere in a
string, inside words or not, offset is the way to go. The code I sent..
well if you have the word "biggest" and search for g, it will hilite the b
because its the first letter of the word, and the length of the word being
searched for is 1. DOH.
So offset is the better choice because it gives you the actual start
position of the string in question, at which point the color change is easy
peasy.
This is where you end up.
on mouseUp
set the traversalOn of field "Results" to true
put the text of field Results into tResults
put the text of field "SearchField" into strSearch
put the length of strSearch into tLength
put 1 into tFramePos
put 0 into tPreviousOffset
repeat while tFramePos <> 0
put Offset(strSearch,tResults,tPreviousOffset) into tFramePos --
change to offset
-- select the right set of chars. The -1 is so that you
--don't count the first char twice, and select an extra. IF that makes
sense.
select char (tFramePos + tPreviousOffset) to (tFramePos +
tPreviousOffset + tLength - 1) of field "results"
set the textColor of the selection to red
put tFramePos + tPreviousOffset into tPreviousOffset
end repeat
select empty
end mouseUp
More information about the use-livecode
mailing list