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

Shared Variable not Calculating as Expected

Status
Not open for further replies.

Hillary

Programmer
Feb 15, 2002
377
US
This is my first attempt at a variable.

In a subreport I have
//Formula Material Cost
Shared NumberVar MaterialCost;
MaterialCost:=Sum ({@Actual Material Cost})
This subreport is in GroupHeader 2C

In the main report I have
//Formual Unit Material Cost
Shared NumberVar MaterialCost;
MaterialCost/{WORK_ORDER.RECEIVED_QTY}
This is in GroupHeader 2A

The formula on the main report is calculating the cost from one line and the quantity from another. For example

P/N Qnty Cost Value Expected Value Returned
A 8 $299.52 $37.44 $0.00
B 2 $103.80 $51.90 $149.76 ($299.52/2)
C 19 $3128.70 $164.67 $5.46 ($103.80/19)
and so on...

Secondly, what is the difference between a Shared Variable and a Global Variable?

Thanks for your help!

Hillary
 
A shared variable is similar to a global variable, with the exception that the shared variable can retain it's value between subreports and the mainreport.

A global variable is exclusive to either the subreport or the main report.

I'm not sure that I can gather exactly how the shared variable isn't calculating as you expect, because you don't seem to give any output examples. What I would recommend though, is starting all your formulas that include variables with the function WhilePrintingRecords;

Naith
 
Thanks Naith.

I figured out the problem. When I moved GroupHeader from 2A to 2C everything calculated correctly. I was trying to use the variable in GH2A before it was declared in GH2C.
 
You are almost there.

Looks like you are evaluating the subreport too late. Try swapping the subreport to 2a and the formula to 2C. Crystal is very logical it does things in a specific order.

Global variable can be shared between formulae in the same report.

Shared variable can be shared between formulae in main and subreports.

Regads

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top