[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Complex Formatting Formula (bg-color) Question

Posted on 2010-01-04
8
Medium Priority
?
352 Views
Last Modified: 2012-05-08
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

0
Comment
Question by:andrecollin
  • 4
  • 3
8 Comments
 
LVL 6

Accepted Solution

by:
magedroshdy earned 1500 total points
ID: 26171109
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 26172128
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
 
LVL 1

Author Closing Comment

by:andrecollin
ID: 31672296
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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
LVL 1

Author Comment

by:andrecollin
ID: 26172918
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
 
LVL 6

Expert Comment

by:magedroshdy
ID: 26178145
"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
 
LVL 1

Author Comment

by:andrecollin
ID: 26178327
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
 
LVL 6

Expert Comment

by:magedroshdy
ID: 26178443
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
 
LVL 1

Author Comment

by:andrecollin
ID: 26178864
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

867 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