Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: HTML highlighting Post Reply Post New Topic
Author Message
katfoxus
Newbie
Newbie
Avatar

Joined: 17 Oct 2011
Location: United States
Online Status: Offline
Posts: 19
Quote katfoxus Replybullet Topic: HTML highlighting
     Posted: 15 Jun 2012 at 3:42am
I have a memo field on my report that I need a the results of the search coming from my stored procedure to be highlighted. I have changed the text interpretation to HTML Text. When I put in the following code I get an error after the first quotations in the HTML that says the remaining text does not appear to be a part of the formula. If I use <b></b> it does bold the desired text but I cannot figure out how to highlight it. Is there anyone that can help with this issue?
 
 
StringVar text_search := uppercase({?@parameter});
Stringvar text_to_search := uppercase({stored_procedure.memo_field});
StringVar Htm1 := "<span style="background-color: #FFFF00">";
StringVar Htm2 := "</span>";
StringVar Result := "";
StringVar Temp := "";
NumberVar Start := 1; 
NumberVar Ln := Len(text_search); 
NumberVar Loc := Instr(text_to_search, text_search); 
While Loc > 0 Do (
    if  Loc - Start = 0 then
    Temp := Htm1 + Mid(text_to_search, Loc, Ln) & Htm2
    Else
    Temp := Mid(text_to_search, Start,  Loc - Start)
            + Htm1 + Mid(text_to_search, Loc, Ln) & Htm2;
   
    Result := Result + Temp; 
    Start := Loc + Ln; 
    Loc := Instr(Start, text_to_search, text_search); 
); 
Temp := Mid(text_to_search, Start); 
Result := Result + Temp; 
Result
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 15 Jun 2012 at 3:55am
Try double quoting;
 
StringVar Htm1 := "<span style=""background-color: #FFFF00"">";

 
Regards,
Ryan.
 
edit: Wouldn't something like this be easier to read/follow;
 
StringVar Htm1:= "<span style=""background-color: #FFFF00"">";
StringVar Htm2:= "</span>";
stringvar search:= {?param};
stringvar text:= {table.field};
numbervar ls:= len(search);
numbervar lt:= len(text);
numbervar p:= instr(text,search,1);
numbervar pa:= if p-1 < 0 then 0 else p-1;
stringvar result:= if p = 0 then text else left(text,pa) & htm1 & search & htm2 & right(text,lt-ls-pa);
result
 
Regards,
Ryan.


Edited by rkrowland - 15 Jun 2012 at 4:26am
IP IP Logged
katfoxus
Newbie
Newbie
Avatar

Joined: 17 Oct 2011
Location: United States
Online Status: Offline
Posts: 19
Quote katfoxus Replybullet Posted: 15 Jun 2012 at 5:40am
I have tried double quoting as well as single in the HTML and the outside. I tried putting 'HTML " " ' and that didn't work either. I can get it to recognize simple HTML codes. I was told using Chrw(13) would work but I've never used it and not sure how to code it.
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 15 Jun 2012 at 5:51am

Hmmm I'm unsure then, do you have to do this with HTML?

 
You could create 3 separate formulas, 1 for each of the following;
string before search criteria
search criteria
string after search criteria
 
You could then place all 3 of these fields into a text box and put a colour only on the Search critera field.
 
Regards,
Ryan.
 
Create 3 formulas, left, mid, right, place the following code in each of them changing r1, r2 & r3 as necassary;
 
stringvar search:= "test";
stringvar text:= "123test4567";
numbervar ls:= len(search);
numbervar lt:= len(text);
numbervar p:= instr(text,search,1);
numbervar pa:= if p-1 < 0 then 0 else p-1;
stringvar r1:= if p = 0 then text else left(text,pa);
stringvar r2:= if p = 0 then "" else search;
stringvar r3:= if p = 0 then "" else right(text,lt-ls-pa);
r1
 
Now place left, mid & right into one text box adding your search highlight to the mid field.
 
Regards,
Ryan.


Edited by rkrowland - 15 Jun 2012 at 5:55am
IP IP Logged
katfoxus
Newbie
Newbie
Avatar

Joined: 17 Oct 2011
Location: United States
Online Status: Offline
Posts: 19
Quote katfoxus Replybullet Posted: 15 Jun 2012 at 10:41am
I still can't get it to work. Thanks for the suggestion though. I know there is a way to do it using ChrW just having trouble figuring it out.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum