Page 1 of 1
highlight text
Posted: Sat Mar 30, 2019 3:03 pm
by micro04
I need to highlight individual words in a field where the word placement is not always the same. The field is populated with a text file that can be changed so the word placement is not always the same.
I have tried :
Code: Select all
set the textColor of fld "Field1" to "green"
which sets all the text to green, I just want a certain words in the field.
Re: highlight text
Posted: Sat Mar 30, 2019 3:29 pm
by Klaus
Hi micro04,
welcome to the forum!
You already said it, since LC is very like the english language, you can actually use all kind of "chunks". That means any part of text like: character, word, trueword, line
Code: Select all
...
set the textColor of word 2 fld "Field1" to "green"
...
set the textColor of word 22 of line 2 fld "Field1" to "red"
...
set the textColor of char 1 of word 22 of line 2 fld "Field1" to "red"
## char = abbreviation for character
...
set the textColor of word 2 to 4 of fld "Field1" to "green"
...
etc.
Best
Klaus
Re: highlight text
Posted: Sat Mar 30, 2019 4:37 pm
by micro04
So how do I highlight the word "test" if I do not know what the location is?
Re: highlight text
Posted: Sat Mar 30, 2019 4:51 pm
by Klaus
Hi micro04,
there are many ways in LC!
I would probably use "wordoffset" first and then use the result to colorize the found word:
Code: Select all
...
put wordoffset("test",fld "Field1") into tFoundWordNumber
## ALWAYS check everything!
## 0 means the string is NOT in that field!
if tFoundWordNumber <> 0 then
set the textColor of word tFoundWordNumber fld "Field1" to "green"
end if
...
This will however only find the first occurrence of "test" in that field.
Read up "wordoffset" (and "offset" and "lineoffset" etc...) in the dicitonary.
Best
Klaus
Re: highlight text
Posted: Sat Mar 30, 2019 4:57 pm
by bogs
Hi micro04,
You can use 'find' (in the dictionary) to find words in the field. I am assuming that although the position of the word may change, the words themselves are in a list of some kind that can be referenced, so if you were going for a one color hilited solution it might look something like (untested) -
Code: Select all
// your list of words in a variable or file or whatever, which we'll call 'yourWords'....
repeat with x=1 to the number of yourWords
find yourword x of field "theFieldYourTextIsIn"
set the textColor of word (yourWord x) of field "theFieldYourTextIsIn" to "green"
end repeat
Make sure you read up on 'find ' and 'repeat' in the dictionary for more accurate examples.
** I see Klaus got back to you, but I'll leave this here as well.