Link to home
Start Free TrialLog in
Avatar of andrecollin
andrecollin

asked on

Complex Formatting Formula (bg-color) Question

Hi,

For my project I have to generate a report in crystal reports, and I'm not that good with it.
- I use" CrystalReports - VS2008"
- I have the following data for my MonthOverview:

  Username | depname | am_1| amReason_1| pm_1 | pmReason_1 | am_2 | amrs_2 | pm_2 | pmrs_2 |...

I used a dummy datasource, because I overwrite the data with data from our own Oracle-DataLayer.

I'm trying to give the textbox, which displays the data of a half day, a background color with the formula below.

I think I wrote some wrong code but I don't know where...
(as you see I tried several split examples...)

Can anyone help me with this?

thx

stringVar varcolor := CStr ({?color0}); 
if CStr ({DataTable1.AMRS_1})='0' then  varcolor := CStr( {?color0})
else if CStr ({DataTable1.AMRS_1})='1' then  varcolor := CStr({?color1})
else if CStr ({DataTable1.AMRS_1})="2" then  varcolor := CStr({?color2})
else if CStr ({DataTable1.AMRS_1})="3" then  varcolor := CStr({?color3})
else if CStr ({DataTable1.AMRS_1})="4" then  varcolor := CStr({?color4})
else if CStr ({DataTable1.AMRS_1})="5" then  varcolor := CStr({?color5})
else if CStr ({DataTable1.AMRS_1})="6" then  varcolor := CStr({?color6})
else if CStr ({DataTable1.AMRS_1})="7" then  varcolor := CStr({?color7})
else if CStr ({DataTable1.AMRS_1})="8" then  varcolor := CStr({?color8})
else if CStr ({DataTable1.AMRS_1})="9" then  varcolor := CStr({?color9})
else if CStr ({DataTable1.AMRS_1})="10" then  varcolor := CStr({?color10})
else stringVar varcolor := "125,116,0";


//stringVar array arr[3];
//arr := Split(varcolor,",",-1);
numberVar varR = ToNumber( Split(varcolor,",")[1]);
numberVar varG = ToNumber( Split(varcolor,",")[2]);
numberVar varB = ToNumber( Split(varcolor,",")[3]);
Color(varR,varG,varB);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of magedroshdy
magedroshdy
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike McCracken
Mike McCracken

What are the values of the 10 color parameters?

How are the values passed?

Why do you need the CStr on the color parameters?

WHen I use CStr on a color I get a number not a RGB-tuple.  crRed = 255, crYellow=65535
I think you need to manipulate the number to get the RGB-tuple out of it.
http://webdesign.about.com/od/color/a/aa012703a.htm

mlmcc
Avatar of andrecollin

ASKER

This worked fine.
but I have a new problem, when I copy this function into the pm_1 field he gives an error about the Vatiable.

"'stringVar varcolor := CStr ({?color0}); ' This field name is not known."

I changed the fields to "{DataTable1.PMRS_1}".

Should the stringVar be "Local"?
This worked fine.
but I have a new problem, when I copy this function into the pm_1 field he gives an error about the Vatiable.

"'stringVar varcolor := CStr ({?color0}); ' This field name is not known."

I changed the fields to "{DataTable1.PMRS_1}".

Should the stringVar be "Local"?

@mlmcc:
i give the colors as a parameter:" report.SetParameterValue("color0", "0,255,0");"
"but I have a new problem, when I copy this function into the pm_1 field he gives an error about the Vatiable." i'm not sure i understand it well, could you write here the code you did ?
the formula I wrote should be copied in all the AM and Pm fields (62 in total).
when I'm gonna copy the formula I only change the datafield nae in to:
"{DataTable1.PMRS_1}" and "{DataTable1.AMRS_2}" and "{DataTable1.PMRS_}" and "{DataTable1.AMRS_3}"...

But, I reuse the variable : "stringVar varcolor" and that's where my  error pops up (I think).

here's the code for multiple fields:
stringVar varcolor := CStr ({?color0}); 
if ToNumber({DataTable1.PMRS_1})=0 then  varcolor := CStr( {?color0})
else if ToNumber ({DataTable1.PMRS_1})=1 then  varcolor := CStr({?color1})
else if ToNumber ({DataTable1.PMRS_1})=2 then  varcolor := CStr({?color2})
else if ToNumber ({DataTable1.PMRS_1})=3 then  varcolor := CStr({?color3})
else if ToNumber ({DataTable1.PMRS_1})=4 then  varcolor := CStr({?color4})
else if ToNumber ({DataTable1.PMRS_1})=5 then  varcolor := CStr({?color5})
else if ToNumber ({DataTable1.PMRS_1})=6 then  varcolor := CStr({?color6})
else if ToNumber ({DataTable1.PMRS_1})=7 then  varcolor := CStr({?color7})
else if ToNumber ({DataTable1.PMRS_1})=8 then  varcolor := CStr({?color8})
else if ToNumber ({DataTable1.PMRS_1})=9 then  varcolor := CStr({?color9})
else if ToNumber ({DataTable1.PMRS_1})=10 then  varcolor := CStr({?color10})
else varcolor := "255,0,255";

Color(ToNumber( Split(varcolor,",")[1]),ToNumber( Split(varcolor,",")[2]),ToNumber( Split(varcolor,",")[3]));

Open in new window

stringVar varcolor should work within all fields without problem, check if DataTable1.PMRS_2 contains null values which prevent it to be converted to number
Oke,Folks,

Just figured out that the DBfields didn't had the same name as I was expecting them.

so there was the problem of the' Field is not known '-error.

thx all for the help.