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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shared Variable off by one 1

Status
Not open for further replies.

cgagnon

Technical User
Oct 12, 2001
14
CA
I have a sub report that totals up the sales tons for a particular customer for a certain date range. The customer number and date range are passed from the main report.
In the sub-report, I have summed the tons in a shared variable and placed them in the Group Footer portion.
I want to show the contents of this shared variable in the Group Footer area for that customer on the main report.
I have defined a shared variable in my main report that just takes the value from the shared variable in my sub-report; I have put this in my Group Footer for that customer. It almost works! except that I am always off by one; the total tons for customer 1 appears on the line for customer 2, the total for customer 2 appears on customer 3 ,etc. Here is how I have defined my variables:

In my subreport: Shared numberVar Tons := Sum ({Company_Sales_History.Net Weight Shipped},{Company_Sales_History.Invoice to Customer Number}) / 2000;

In my main report: Shared numberVar Tons;

Does anyone know what I am doing wrong?


 
How many decimals do you want...is it a rounding issue?? Also check the format of the number in the main report...sometimes the rounding and display for the numeric format are not right
 
Thank you for your answer, but no, it is not a rounding issue. The tons are correct, it is just that they appear for the wrong customer. The tons for customer 1 appear on the line for customer 2...
 
Make sure that the formula in the main report is in a section that occurs after the subreport is complete. This might mean splitting the GF section into two pieces (A and B) and putting the subreport in A and the formula in B. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
Thank You! That did the trick! The only problem now is that I would like to have a grand total of the tons that are in the group footer. I can't seem to get it to work.
My shared variable that I pass from my sub-report is called Tons. In my main report, I defined a formula called ShareTonsMain as follows:

WhilePrintingRecords;
Shared numberVar Tons;
Tons;

I want to total these in my main report footer, so I tried defining a formula of sum(tons), and I also tried sum(ShareTonsMain), but Crystal won't take either one.
Next, I tried to accumulate my tons as I display them, so I changed my ShareTonsMain formula to be as follows:

WhilePrintingRecords;
Shared numberVar Tons;
Global numberVar accum_tons:= accum_tons + Tons;
Tons;

And I then defined a formula called TotalTons as follows:

Global NumberVar accum_tons;
accum_tons;

which I placed in my report footer.

It gives me a zero.

Am I going at it the wrong way? (obviously I am...)




 
See the FAQ on running totals in the General forum. You will need the 3-formula technique. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top