Solved

set fields (background-)color according to value of other field

Posted on 2004-10-20
6
572 Views
Last Modified: 2006-11-17
hello experts,

i'm using crystal-reports embedded into visual studio 2003.

i have some linked tables. the datatable A holds a state-id belonging to another small table B that has concrete informations on how to show the value (text, color, backgroundcolor, ...).

now i  have the text-field B_1 of B on my report showing the user-readable value. according to the state-id A_1 of table A i'd like to set the textcolor and backgroundcolor of B_1 which is shown to the user. i'm lost on how to colorize that field. does anyone of you have a concrete solution?

my problem is, that i do not have experience using cr's formula language. i thought of using a switch and strcmp on A_1. then according to the result set the color and backgroundcolor of B_1 to certain values.

Switch (
    StrCmp ({A.A_1}, "offr"), colorizeMyField,
    StrCmp ({A.A_1}, "inf"),  colorizeMyFieldOtherWay,
    StrCmp ({A.A_1}, "inf"),  colorizeMyFieldOtherWay
)

do i have the right direction? can anyone of change my code the way it sets the forecolor and the backcolor of field {B.B_1} according to {A.A_1}?

thank you in advance
0
Comment
Question by:kolpdc
  • 4
  • 2
6 Comments
 
LVL 42

Accepted Solution

by:
frodoman earned 500 total points
Comment Utility
rt-click on the field to be colored {B.B_1} and select Format -> Border.  Click the formula button (X+2) to the right of "Background" and enter a formula like this:

If {A.A_1} = 'offr' then
   crRed
else if {A.A_1} = 'inf' then
   RGB(200, 170, 35)
else crDefault

That'll set the background based on the A.A_1 field.  To set the foreground do the same process on the Format -> Font tab.

Crystal doesn't support the "Switch" command but it does support the VB "Select...Case" version if you prefer that to the if..then statements.

If any part of this isn't clear please let me know.

frodoman
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
A little clarification to my previous post:

The color set can be either a Crystal constant (crRed, crWhite, etc.) or you can customize it with the RGB function which takes the form "RGB(0-255 Red, 0-255 Green, 0-255 Blue)" -- I've shown examples of both above.  If you use the crDefault then it'll be set to whatever color you've picked from the color-picker on the Format -> Border tab after putting a checkmark in the 'Background' field.

If you want to use the Select..Case structure it goes like this:

select {A.A_1}
 case 'offr' : crRed
 case 'inf'   : RGB(100, 100, 100)
 default: crDefault

HTH

frodoman
0
 
LVL 4

Author Comment

by:kolpdc
Comment Utility
thank you. i'll check it. by the way - i've seen the following statement in my studios formula designer

Switch (expr1, function1, expr2, function2, ...)
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 42

Expert Comment

by:frodoman
Comment Utility
I double-checked and you're right, the switch statement is in there.  Apparently it's been added at some version and I never noticed it appeared.  Obviously the syntax is different then what you had but certainly you could still use switch instead of the select..case or if..then.

frodoman
0
 
LVL 4

Author Comment

by:kolpdc
Comment Utility
thank you frodoman - it just works fine.
wish you a nice time for rest of night, day, evening (take the one fitting your needs ;)...
0
 
LVL 42

Expert Comment

by:frodoman
Comment Utility
Glad I could help - frodoman
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Crystal Reports - Display Last Invoice in Group 15 58
How to add a total 6 24
Next Full Week 4 61
Business Object Server 2 20
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now