Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Compare Fields with RTF Formatting Post Reply Post New Topic
Author Message
CIW George
Newbie
Newbie


Joined: 05 Apr 2010
Online Status: Offline
Posts: 4
Quote CIW George Replybullet Topic: Compare Fields with RTF Formatting
     Posted: 05 Apr 2010 at 6:25am

I have two fields I want to compare in CR 2008. If the fields are different, I want them both to be red; if they're the same, they're both black. I have done this many times with "standard" fields in CR and the conditional formatting works fine.

 
Now, my problem.
 
I have a table in VS 2008 that drives the CR report. The contents of each of the two fields to be displayed contain text or numeric data. If the record is text, I leave it alone. If the record is numeric, I replace the record with RTF formatting to align the decimal point ("\lixxx") so when the report is run, all the decimal points line up (rather than being displayed with a ragged right side - simulating a decimal tab). Both fields in CR are set for RTF text interpretation. When the report is run, the fields are formatted exactly how I want them.
 
(Note:  In this report, I cannot use right flush in the field because the field is quite wide to allow room for the text, and I want the numeric values to be as close to the left side of the field as possible.)
 
 
The problem is, only those fields with text (no RTF formatting) are compared correctly - those that are different are highlighted in red. The numeric fields (with RTF formatting) don't compare correctly - the differences are not highlighted.
 
 
The records with text contain only the text (no RTF headers or formatting); the records with numbers contain the RTF header, formatting information, and the value.  If I shut off RTF text interpretation for these fields, the RTF format strings are compared correctly.
 
 
Here's what I am sending to CR for numeric values:
 
    "{\rtf1\ansi\deff0 {\fonttbl{\f0 Arial;}}" & str_RTF_Indent & " \fs16 " & sng_RTF_Value, where:

        'sng_RTF_Indent' is the left indent I need to align the decimals ("\lixxx", where xxx is the number of twips to indent)
        'str_RTF_Value' is the text string of the number to be displayed. 

 

Here's the formula I have in both fields to compare the two fields:

 
    if {Catalog_Table_Report.Value 1} <> totext{Catalog_Table_Report.Value 2} then
        formula = crRed
    end if
 

The numeric alignment works perfect, I just can't compare the two fields when Text Interpretation is set to RTF.

 
If I create a formula field in CR for testing purposes only:
  

    {Catalog_Table_Report.Value 1} = {Catalog_Table_Report.Value 2}

 
The field correctly reports true or false depending on whether Value 1 and Value 2 are equal.
 

Does CR not compare fields when they are RTF formatted, or is there something I'm missing?

 
Thank you in advance for your help!


Edited by CIW George - 05 Apr 2010 at 6:29am
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 05 Apr 2010 at 10:01am
Part of the problem may be in your formula itself.  Unless it's a typo, you're missing ToText on one side.  Also, you don't need "formula=" and "end if".  Try this:
 
if ToText({Catalog_Table_Report.Value 1}) <> ToText({Catalog_Table_Report.Value 2}) then
        crRed

 
If that doesn't work, here's another idea:
 
If I create a formula field in CR for testing purposes only:

    {Catalog_Table_Report.Value 1} = {Catalog_Table_Report.Value 2}

The field correctly reports true or false depending on whether Value 1 and Value 2 are equal.
 
If this works correctly, try using it instead.  For this example, I'll call the formula {@FieldsEqual}.  So your formula to set color would be:
 
if not {@FieldsEqual} then
  crRed
 
-Dell


Edited by hilfy - 05 Apr 2010 at 10:01am
IP IP Logged
CIW George
Newbie
Newbie


Joined: 05 Apr 2010
Online Status: Offline
Posts: 4
Quote CIW George Replybullet Posted: 05 Apr 2010 at 10:42am
The missing "ToText" was a typo - sorry.
 
I believe if you're using Basic Syntax rather than Crystal Syntax, you need the "formula=" and "end if".
 
I tried keying the field color off the @FieldsEqual field, but Value 1 and Value 2 remain black, regardless of the status of the @FieldsEqual (which correctly indicates true/false for Value 1 and Value 2).
 
It's almost like CR is ignoring the formatting formula if it's doing RTF Text Interpretation.  If CR doesn't see the RTF header ("{\rtf1\ansi\deff0 ...), it looks at the formatting formula(s) to see what to do; if CR sees the RTF header, it ignores the formatting formula(s).
 
Although I can do the the RTF coloring in the table before CR gets it, it would be nice to confirm that CR does ignoring formatting formulas with RTF formatting.
 
Thoughts?
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