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

LVL 1
andrecollinAsked:
Who is Participating?
 
magedroshdyCommented:
try the following
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 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(ToNumber( Split(varcolor,",")[1]),ToNumber( Split(varcolor,",")[2]),ToNumber( Split(varcolor,",")[3]));

Open in new window

0
 
mlmccCommented:
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
0
 
andrecollinAuthor Commented:
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"?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
andrecollinAuthor Commented:
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");"
0
 
magedroshdyCommented:
"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 ?
0
 
andrecollinAuthor Commented:
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

0
 
magedroshdyCommented:
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
0
 
andrecollinAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.