INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Highlighting Parameter Search Results in Text Field

Highlighting Parameter Search Results in Text Field

(OP)
This is stumping me. The following is the formula I'm using to highlight key words I'm searching a text field for in my database. I need it to highlight/color the word each time it is found in a sentence.

The table and field is {ChatMessages.MESSAGE}
The prompt is {?Text_To_Search_for}
I have set text interpretation in format field to HTML

local stringvar notes:=lcase({ChatMessages.MESSAGE});
local numbervar i;
for i:=1 to count({?Text_To_Search_for}) do (
notes:=replace(notes,{?Text_To_Search_for}[i],"<font color=#ff0000>" & {?Text_To_Search_for}[i] & "</font>",1,-1,1);
);
notes

Can someone please assist me with this? Any direction/clarification is greatly appreciated. Thank you.

Mike

RE: Highlighting Parameter Search Results in Text Field

(OP)
Thank you. I thought the solution was here. It errors "Local StringVar ValueToSearch := {?Text_To_Search_for};" and says "This array must be subscripted..." I'm simply plugging in my database.field and the parameter. Any idea why its failing?

RE: Highlighting Parameter Search Results in Text Field

Try the following:

replace(lowercase({ChatMessages.MESSAGE}), {?Text_To_Search_for},"<font color=#ff0000>" & {?Text_To_Search_for} & "</font>")

RE: Highlighting Parameter Search Results in Text Field

(OP)
Nope. Still states this array must be subscripted. I subscripted your code as follows and replaced the line in my code:

replace(lowercase({ChatMessages.MESSAGE}), {?Text_To_Search_for}[i],"<font color=#ff0000>" & {?Text_To_Search_for}[i] & "</font>")
);

I got no errors but the text shows with no highlight

RE: Highlighting Parameter Search Results in Text Field

I did it this way, and it returned the result I think you are looking for:

CODE

Replace({Table.Field}, {?Text_To_Search_for}, '<font color=#ff0000>' + {?Text_To_Search_for} + '</font>') 

I suspect the error message you are getting is because your parameter allows for multiple values. If that is actually required you would need to loop through for the text for each of the parameter entries, like this:

CODE

WhilePrintingRecords;
Local NumberVar i;
Local StringVar RESULT := {Table.Field};

For i := 1 to UBound({?Text_To_Search_for}) Do
(
    RESULT := Replace(RESULT, {?Text_To_Search_for}[i], '<font color=#ff0000>' + {?Text_To_Search_for}[i] + '</font>')
);

RESULT 

Hope this helps.


Cheers
Pete

RE: Highlighting Parameter Search Results in Text Field

(OP)
Thank you, Pete. I modified my code to match yours:

WhilePrintingRecords;
local numbervar i;
Local stringvar Note := lcase({ChatMessages.MESSAGE});
for i:=1 to count({?Text_To_Search_for}) do (
Note:= Replace(Note, {?Text_To_Search_for}[i],'<font color=#ff0000>' + {?Text_To_Search_for}[i] + '</font>')
);
Note

I replaced {table.field} with the text field from my database that I want to search {ChatMessages.MESSAGE}. Still did not work. I copied yours verbatim making the one change to {table.field} . Still didn't work.

I believe placing it in the Details section is the correct location and I simply suppress duplicates. I used ubound and count but didn't make a difference. Betty, Pete any other ideas? I didn't think this would so complicated.

RE: Highlighting Parameter Search Results in Text Field

Have you formatted the formula to HTML text? If not, change the text interpretation by right clicking the formula; select Format Field->Paragraph(tab)->Text Interpretation:HTML text.
I forgot to specify it in my previous post, but in the link I first sent, it was mentioned in the post by lbass.

RE: Highlighting Parameter Search Results in Text Field

(OP)
Yes. I changed to HTML text interpretation. This has me stumped.

RE: Highlighting Parameter Search Results in Text Field

I tested your last formula and it worked. Be sure that you are putting the formula on your report instead of the message field, and that you are formatting the formula to HTML text interpretation.

-LB

RE: Highlighting Parameter Search Results in Text Field

(OP)
Thank you. Now I really am lost. I created a formula called "highlight". I put it in the details section of the report. I get no errors but the result displays in black font. Is there another formula I could try?

RE: Highlighting Parameter Search Results in Text Field

Try creating a new report and add the following formula:

@highlight

stringvar txt:="Hello World!";
replace(txt, "Hello","<font color=#ff0000>" & "Hello" & "</font>")


Right click the formula; select Format Field->Paragraph(tab)->Text Interpretation: HTML text and see if Hello is displayed in Red font.

RE: Highlighting Parameter Search Results in Text Field

I tested my solution before posting so I know it should work.

If you are prepared to post a copy of your report file (with saved data) I'd be happy to take a look.


Cheers
Pete

RE: Highlighting Parameter Search Results in Text Field

(OP)
Betty,

Your formula works. Hello is in red.

Pmax9999,

Unfortunately, I can't.

Question: I have 174 search terms. In the "default" list of my prompt, I imported a .txt file containing the terms surrounded with an *. The report works but it does not color those search terms red.

When I removed the * from both ends of the term, the report finds nothing.

To account for the *, I put {ChatMessages.MESSAGE} like "*"+{?Text_To_Search_for}+"*" in the select expert. This produced a hit on everything in the database including the search terms so that doesn't work.

Could this be my problem?

RE: Highlighting Parameter Search Results in Text Field

Is the parameter being used for both record selection and for your search? Is the reason for having the wildcard at both ends so that the report returns all records where the field contains the particular words?

Out of curiosity, can you create a second parameter that doesn't include the wildcard, and use that in the highlighting formula. If that works, we can look at a solution that will strip the wildcard out of the parameter when it is being used in the highlight formula.



Cheers
Pete

RE: Highlighting Parameter Search Results in Text Field

The following code will strip the wildcards from the parameter in the search/highlight formula:

CODE

WhilePrintingRecords;
Local NumberVar i;
Local StringVar RESULT := {Table.Field};


For i := 1 to UBound({?Text_To_Search_for}) Do
(
    RESULT := Replace(RESULT, Replace({?Text_To_Search_for}[i], '*', ''), '<font color=#ff0000>' + Replace({?Text_To_Search_for}[i], '*', '') + '</font>')
);

RESULT 

Please let us know how this goes.

Cheers
Pete

RE: Highlighting Parameter Search Results in Text Field

(OP)
Thank you, thank you, thank you.

Here is the final formula:

WhilePrintingRecords;
local numbervar i;
Local stringvar Note := lcase({ChatMessages.MESSAGE});
for i:=1 to ubound({?Text_To_Search_for}) do (
Note := Replace(Note, Replace(lcase({?Text_To_Search_for}[i]), '*', ''), '<font color=#ff0000>' + Replace(lcase({?Text_To_Search_for}[i]), '*', '') + '</font>')
);
Note

It was the * and lcase that I needed to deal with.

RE: Highlighting Parameter Search Results in Text Field

Glad it helped.

Cheers
Pete

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close