Crystal Report Tips

Thursday, March 23, 2006

Time taken to generate Crystal Report

To display the time it takes for a crystal report to run, add a subreport at the report footer section of your main report. Setup the subreport to return one row of data. Add a new formula field and copy the following code into it. Add this formula field to the report header of your subreport. That's it your done.
The trick is to use CurrentDate, CurrentTime and DataDate, DataTime.
The CurrentDate and CurrentTime will give the date time that the report started generating.
The DataDate and DataTime will give the date time that the subreport started generating.

=================

Shared timevar StartTime;
Shared timevar EndTime;
Shared datevar StartDate;
Shared datevar EndDate;
numbervar Hours;
numbervar Minutes;
numbervar Seconds;
numbervar ElapsedTime;
numbervar ElapsedDays;
stringvar Display;

StartTime := CurrentTime;
StartDate := CurrentDate;
EndTime := datatime;
EndDate := datadate;

ElapsedDays := EndDate - StartDate;

if StartTime <= EndTime then ElapsedTime := ElapsedDays*24*60*60 + (EndTime - StartTime) else ElapsedTime := ElapsedDays*24*60*60 - (24*60*60-(EndTime - StartTime)); Seconds := abs(ElapsedTime mod 60); Minutes := abs(Truncate(ElapsedTime/60) mod 60); Hours := Truncate(ElapsedTime/3600); Display + ToText(Hours,0)+' Hours ' + ToText(Minutes,0)+' Minutes ' + ToText(Seconds,0)+' Seconds '; Display := 'Generation Time: '; if abs(Hours) > 1 then
Display := Display + ToText(Hours,0)+' Hours '
else if abs(Hours) > 0 then
Display := Display + ToText(Hours,0)+' Hour ';

if Minutes > 1 then
Display := Display + ToText(Minutes,0)+' Minutes '
else if Minutes > 0 then
Display := Display + ToText(Minutes,0)+' Minute ';

if Seconds > 1 then
Display := Display + ToText(Seconds,0)+' Seconds '
else if Seconds > 0 then
Display := Display + ToText(Seconds,0)+' Second ' ;

Display;

Monday, March 20, 2006

Greetings

Welcome to crystal tip where I will discuss some of the great things I have learned writing Crystal Reports.