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

How to Sum Values from Two Subroutines - 1

Status
Not open for further replies.

MrFuzzwah

MIS
Mar 28, 2011
49
US
Hello -

I suspect this is easier that it appears but as a CR newb it is not for me!

I have two subroutines that each yield a total field. I need to sum these two in the main report. I'm not sure how to do that - I've been trying to use a shared variable but my results in the subroutines are derived from Select Expert and I have not figured out how to add variables to them.

I am on CR 11.0 / Windows XP

Thanks
 
To get a value from a subreport to the main report, do something like
Code:
whileprintingrecords;
shared currencyvar SumSaved;
SumSaved:={#TotSaved};
SumSaved
And to access it in the main report, create another formula field with
Code:
whileprintingrecords;
shared currencyvar SumSaved;
SumSaved

Note that the shared variable is only available in the section after the section which contains the subreport.

For two subreports, use two different shared variable names. Display them while developing your report, just to be sure it works. Then add the two fields in the main report.

You can also pass values down to a subreport, using Edit > Subreport Link. Such links are automatically treated as record selection rules, but you can get rid of those and read the rules. This could mean you do the addition in the second subreport.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 2008 with SQL and Windows XP [yinyang]
 
I am trying to add the result of two subroutines but the formula is returning a value of zero.

In subroutine 1 (named Taxable) I have:
whileprintingrecords;
shared currencyvar SumSaved1;
SumSaved1:={#Taxable Wages};
SumSaved1

In subroutine 2 (names NonTaxDeds) I have:
whileprintingrecords;
shared currencyvar SumSaved2;
SumSaved2:={#NontaxDeds};
SumSaved2

In the main report I have:
{@Taxable} + {@NonTaxDeds}

Am I referring to the routines incorrectly? Or - is it a section problem - both the subroutines are in Group Header 1 and do return values corectly but the sum is in the next section which is returning zero incorrectly. I hope this makes sense?
 
MrFuzzwah, thanks for the star, but you should also explain what you finally did, so that others can use the thread for reference.

I assume it was using the same name for the Shared Variable: the name of the formula field that contains it does not matter.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 2008 with SQL and Windows XP [yinyang]
 
I 'starred' as I appreciated the response. Regarding my program - It has not been resolved - I can't get it to work.

I am trying to add the result of two subroutines but the formula is returning a value of zero.

In subroutine 1 (named Taxable) I have:
whileprintingrecords;
shared currencyvar SumSaved1;
SumSaved1:={#Taxable Wages};
SumSaved1

In subroutine 2 (names NonTaxDeds) I have:
whileprintingrecords;
shared currencyvar SumSaved2;
SumSaved2:={#NontaxDeds};
SumSaved2

In the main report I have:
{@Taxable} + {@NonTaxDeds}


Am I referring to the routines incorrectly? Or - is it a section problem - both the subroutines are in Group Header 1 and do return values corectly but the sum is in the next section which is returning zero incorrectly. I hope this makes sense?

 
Please do not double post I have answered this question on you other posting on same subject

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top