Page 1 of 1

Formula

Posted: Sat Jan 05, 2008 5:44 am
by Siang Hwee
Hi. I am trying to migrate from crystal report to stimulReport. I wonder how to Add a formula field? The reason is I want to sum up all the total for a column Call Total Work Hour as shown below

Name Total Work Hour
Billy 3:33
Jasicca 12:33
Daniel 12:00

Total 28:06

As shown above. The total cannot be using the Sum function. I have to write my own formula in order to sum the hour which is in string format. Last time i was using crystal report formula fields to settle the problem, but i have no idea how the stimulReport formula fields work.

Hope can get help from the expert. Thanks

Formula

Posted: Mon Jan 07, 2008 6:08 am
by Vital
You can do following steps:

1. Add variable to report dictionary which will be store result of calculating.
2. In Rendering event of DataBand place code for calculating total. For example:

Code: Select all

variable += value;
3. At footer band (or in any other component) place textbox. Set property ProcessAtEnd of this textbox to true. Type in text expression:

Code: Select all

{variable}
Thank you.

Formula

Posted: Tue Jan 08, 2008 2:35 pm
by Siang Hwee
Hi Vital,

Thanks for your reply. The problem now is i need to use some expression. As I shown you before. The value are all time, they are string in my system. I need to split them to hour and minutes using delimeter ":". sum up all hour and minutes seprately. Then convert minute to hour. Then only possible to get the total.

For the case i quoted before,
Total hour = 3 + 12 + 12 = 27
Total Minute = 33 + 33 = 66
Final Total Hour = 27 + (66 / 60) = 28
Final Total Minute = 66 - 60 = 6

Final Result will be 28:06


As you may see. i need to split using the time by ":" first before i can sum them up. I just wonder is it possible to do my own formula like crytal report.
Thanks for help

Vital wrote:You can do following steps:

1. Add variable to report dictionary which will be store result of calculating.
2. In Rendering event of DataBand place code for calculating total. For example:

Code: Select all

variable += value;
3. At footer band (or in any other component) place textbox. Set property ProcessAtEnd of this textbox to true. Type in text expression:

Code: Select all

{variable}
Thank you.

Formula

Posted: Wed Jan 09, 2008 4:38 am
by Edward
Yes it is possible to sum up the values in the format of the DateTime. For this instead of the

Code: Select all

variable += value;
expression, please write the following:

Code: Select all

variable = variable.AddHours(variable.Hour).AddMinutes(variable.Minute);
variable must be declared as DateTime type.

The expression in the textbox from Vital's answer also may be represented as required. For this just right-click the textbox and setup the format you need.

There is another way to achieve the goal is Calculated Columns which is similar to Formula Fields in Crystal Reports. The following flashing tutorial will help you to start work with this columns:

http://www.stimulsoft.com/livedemos/Rep ... ields.html

Thank you.

Formula

Posted: Wed Jan 09, 2008 7:31 am
by Siang Hwee
Hi Edward,

I can't declare as DateTime type, because the total might be 123:45 which means total working time is 123 hours 45 minutes. Hence i store the time in string type, besides, i also store the time in minute as (123 * 60) + 45 = 7425 minutes. Do you think is it possible to sum the minute first then convert it to time? Is stimul report have something like formula where i can write my own formula probably based on c# or vb script like crystal report?

Besides, is there any help file for formula so that i can refer to?

Thanks again for help.


Edward wrote:Yes it is possible to sum up the values in the format of the DateTime. For this instead of the

Code: Select all

variable += value;
expression, please write the following:

Code: Select all

variable = variable.AddHours(variable.Hour).AddMinutes(variable.Minute);
variable must be declared as DateTime type.

The expression in the textbox from Vital's answer also may be represented as required. For this just right-click the textbox and setup the format you need.

There is another way to achieve the goal is Calculated Columns which is similar to Formula Fields in Crystal Reports. The following flashing tutorial will help you to start work with this columns:

http://www.stimulsoft.com/livedemos/Rep ... ields.html

Thank you.

Formula

Posted: Wed Jan 09, 2008 9:25 am
by EDV Gradl
You write write your own class in an external library (.dll) and use that in Stimulsoft. Everything that is .net can be used.

Marco

Formula

Posted: Fri Jan 11, 2008 1:28 am
by Siang Hwee
Thanks Marco. i will try it out.
EDV wrote:You write write your own class in an external library (.dll) and use that in Stimulsoft. Everything that is .net can be used.

Marco