Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Highlighting specific text in a notes field 1

Status
Not open for further replies.

Stewman

MIS
Jan 23, 2002
79
US
Hello,

I have a notes field that contains multiple lines of text. I would like to highlight red certain specific words when present, not the whole field. I am in the text interpretation field and have used the following formula which I have found on other postings. In this example I want to highlight the word PASSED

Shared StringVar SearchText := "PASSED";
StringVar Htm1 := "<font color=#800000>";
StringVar Htm2 := "</font>";
StringVar Result := "";
StringVar Temp := "";
NumberVar Start := 1;
NumberVar Ln := Len(SearchText);
NumberVar Loc := Instr({MPD_CASE_TYPE_LIST.MPD_MONO}, SearchText);
While Loc > 0 Do (
Temp := Mid({MPD_CASE_TYPE_LIST.MPD_MONO}, Start, Loc - Start) + Htm1 + Mid({MPD_CASE_TYPE_LIST.MPD_MONO}, Loc, Ln) & Htm2;
Result := Result + Temp;
Start := Loc + Ln;
Loc := Instr(Start, {MPD_CASE_TYPE_LIST.MPD_MONO}, SearchText);
);
Temp := Mid({MPD_CASE_TYPE_LIST.MPD_MONO}, Start);
Result := Result + Temp;
Result

After trying to save I get the notice formula result must be a number. This happens in other attempts where I have tried other code. Any idea as to what I'm doing wrong?
 
Try:

Code:
WhilePrintingRecords;

Local NumberVar i := 1;
Global StringVar OUTPUT;
Shared StringVar SearchText := "PASSED";

For i := 1 to Ubound(Split({Table.Field}, SearchText)) Do
Output := Output + Split({Table.Field}, SearchText)[i] + 
If      i <> Ubound(Split({Table.Field}, SearchText))
Then    '<font color=#800000>' + SearchText + '</font>';

OUTPUT

Cheers
Pete
 
Hi Pete,

Thanks for the response. I have tried this method also and I get the same message. The formula result must be a number. Any idea as to why I get this message? The field is varchar.

Thanks,

Chris
 
My code did have a basic flaw in it, but that won't have caused the problem you have. It should have been:

Code:
WhilePrintingRecords;

Local NumberVar i := 1;
Local StringVar OUTPUT;
Global StringVar SearchText := "Shit";

For i := 1 to Ubound(Split({Table.Field}, SearchText)) Do
Output := Output + Split({Table.Field}, SearchText)[i] + 
If      i <> Ubound(Split({Table.Field}, SearchText))
Then    '<font color=#800000>' + SearchText + '</font>';

OUTPUT

The code provided is intended to go into a formula, which would then be placed on the report instead of the note field, with the Text Interpretation format set to HTML.

Is that how you are using the code?

An even simpler approach would be to use Replace, as in the following example:

Code:
Replace({Table.Field}, 'PASSED', '<font color=#800000>' + 'PASSED' + '</font>')

It will still be necessary to set the Text Interpretation to HTML.

Hope this helps.

Cheers
Pete


 
Thanks Pete, that worked. My problem was I was putting it in the x-2 box next to text interpretation instead of a formula.
 
Pete one more question. Is it possible to search for multiple key words and only highlight those words even if found in the same record?
 
Absolutely. For this, the Replace approach is definitely simplest. Using a 'nested' Replace approach as follows worked in my testing:

Code:
If      {Table.Field} LIKE ["*PASSED*FOUND*", "*FOUND*PASSED*"]
Then    Replace(Replace({Table.Field}, 'PASSED', '<font color=#800000>' + 'PASSED' + '</font>'), 'FOUND','<font color=#800000>' + 'FOUND' + '</font>')
Else    {Table.Field}

In my test, I was looking for "PASSED" and "FOUND", but without regard for which appears first, and when both found it changed both words to red. In the event that only one of the words is found it does nothing.


Cheers
Pete
 
Once again you have done it. That worked. Thanks Pete.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top