Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Computation problem in Crystal Report

Status
Not open for further replies.

reycons

Instructor
Mar 29, 2008
21
0
0
PH
Indate Timein Outdate Timeout # of Hours Remarks

09/16/08 8:00 AM 09/16/08 6:00 8 VL
09/17/08 8:00 AM 09/17/08 6:00 8 VL
09/18/08 8:15 AM 09/17/08 6:05 8
---------------------------------------------------------
Total no. of Hours 24
Total no. of VL 0

As you can see, this is the format of my Crystal report in my program. The total no of hours is correct but the only problem is the Total no. of VL which is 0 instead of 16.

Here is my code to get the Total no. of VL which the basis for the computation of VL is the VL remarks using the formula fields which i think is wrong because it didn't get the correct result:

shared numbervar totalvl;
whileprintingrecords ;

totalvl := 0;
if {TempDTR_Total.Remarks} ="VL" then
totalvl := cdbl(totalvl) + {TempDtr_Total.TotalTime};
totalvl;

Hoping you could help me regarding this...
Thanks in advance...



 
You don't need shared variables unless you are linking to a subreport. You don't need variables at all in most cases, it is easier to use a Running Total. Set it to add when the 'Remarks' is VL.

The use of Crystal's automated totals is outlined at FAQ767-6524. Very well worth getting to know.

PS. I think your formula fails because you are not saving the existing value when it is not VL. But let Crystal do the work.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
I tried exploring the Running total. But could you give me some sort of simple coding which shows the comptation. I find it difficult to get the answer. I used the formula in the running total.

numbervar totalvl;
whileprintingrecords ;

totalvl := 0;

if {TempDTR_Total.Remarks} ="VL" then
totalvl := totalvl + 8

As you,ve said Madawc (Programmer), there should be no variables involved but i remove the variables then I got an error. Maybe you could show me some of your sample codes that relates to my problem..

Please help me up guys...
Thanks in advance...
 
This may help you get started:

Open the Field Explorer

Create a new Running Total field: VL TOT with the following parameters:
Field to Summarize = # of Hours

Evaluate
Beside "Use a formula" click in the X-2 and enter:
if {Remarks}="VL" then true
Click Save and Close

Click OK

Place the running total field VL TOT in the detail line of your report
Donal
 
To correct your variable formula:

//for the detail section:
whileprintingrecords ;
numbervar totalvl; //do not set it to zero
if {TempDTR_Total.Remarks} ="VL" then
totalvl := totalvl + {TempDtr_Total.TotalTime};

//{@display} for the footer:
whileprintingrecords ;
numbervar totalvl;

If you are doing this at the group level, you would need a separate reset formula for the group header:

whileprintingrecords;
numbervar totalvl;
if not inrepeatedgroupheader then
totalvl := 0;

But you don't need these formulas at all. Just create one formula:

if {TempDTR_Total.Remarks} ="VL" then
{TempDtr_Total.TotalTime}

Place this in the detail section and right click->insert summary->insert a sum on it at the group and/or report level.

-LB
 
Thanks for your help. I already solve the problem but there's another problem that arise. Let me show you now the format of my report and the problem that arises.

Name of Employee: Mark Cuevaz

Indate Timein Outdate Timeout # of Hours Remarks

09/16/08 8:00 AM 09/16/08 6:00 8 VL
09/17/08 8:00 AM 09/17/08 6:00 8 VL
09/18/08 8:15 AM 09/17/08 6:05 8
---------------------------------------------------------
Total no. of Hours 24
Total no. of VL 16

Name of Employee: Jerry Cruz

Indate Timein Outdate Timeout # of Hours Remarks

09/16/08 8:00 AM 09/16/08 6:00 8
09/17/08 8:00 AM 09/17/08 6:00 8
09/18/08 8:15 AM 09/17/08 6:05 8
---------------------------------------------------------
Total no. of Hours 24
Total no. of VL 16


I used the formula using the formula fields:

numbervar totalsl;

whilereadingrecords;

if {Tempdtr_Total.Remarks} = "SL" then
totalsl := cdbl(totalsl) + {TempDtr_Total.TotalTime};
totalsl;

Now the problem is the computation of VL because if the VL is zero(0) in the second employee still it put up a number 16 which was the VL of the first employee.


 
As I said in my last post, you need a reset formula. Again, you don't even need to use a variable and the corresponding three formulas to do this. You could have just used a conditional formula as I mentioned at the end of my last post. Much simpler.

-LB
 
PS. Your formula should also use "whileprintingrecords"--not whilereadingrecords.

-LB
 
flemard (TechnicalUser) 8 Dec 08 22:50
This may help you get started:

Open the Field Explorer

Create a new Running Total field: VL TOT with the following parameters:
Field to Summarize = # of Hours

Evaluate
Beside "Use a formula" click in the X-2 and enter:
if {Remarks}="VL" then true
Click Save and Close

Click OK

Place the running total field VL TOT in the detail line of your report
Donal

Thank you so much all of you guys... Most of all thanks to this post by flemard (TechnicalUser). This is the post that I apply and it gets the precise answer. thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top