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!

HELP! Urgent! Shared Variables not returning proper values

Status
Not open for further replies.

cheerfulskeptic

Programmer
Feb 3, 2003
88
IN
Hi,
I have a simple report - Group A, Group B (which contains a subreport). I am trying to get a running total of records inside each subreport and print it out at th end.
I declare a shared variable, say VarA and set it to 0 at the report header.
Then inside the subreport, I say VarA = VarA + {@total}.
Then I printit out at the end.
Hwoever, whenever it reaches a zero value inside the subreport, it tanks. I've even put a clause that says if @total > 0 then VarA = VarA + {@total} but it doesnt return the correct values (ie, it sorta resets the shared variable back to a different number.)

here are my formulas:
Report Header:
whileprintingrecords;
shared numbervar numCatsLY := 0;

Inside Footer of Subreport:
whileprintingrecords;
if {@TotLY} > 0 then
shared numbervar numCatsLY := shared numbervar numCatsLY + {@TotLY} ;

at Report Footer (final value to be displayed)
whileprintingrecords;
shared numbervar numCatsLY ;
numCatsLY


What seems to be the problem?
Thanks in advance!



 
Try altering the subreport formula:

Report Header:
whileprintingrecords;
shared numbervar numCatsLY := 0;

Inside Footer of Subreport:
whileprintingrecords;
shared numbervar numCatsLY;
if {@TotLY} > 0 then
numCatsLY := numCatsLY + {@TotLY} ;

at Report Footer (final value to be displayed)
whileprintingrecords;
shared numbervar numCatsLY

-k
 
no luck :(

the formula {@TotLy} is a formula as such:

numberVar totcatpurch := 0;
numberVar totcatcredit := 0;

if isNull ({#totLYCathSales}) then
totcatpurch := 0 else totcatpurch := {#totLYCathSales};

if isNull ({#TotLYCathSalesCR}) then
totcatcredit := 0 else totcatcredit := {#TotLYCathSalesCR};

totcatpurch - totcatcredit


where {#totLYCathSales} and {#totLYCathSalesCR} are 2 running totals from a Pervasive SQL database (I have to use the formular @TotLy to calculate the difference because the Pervasive SQL returns null values for zero's.
 
What does no luck mean? Your formula probably has no bearing on this (though I probably wouldn't be using Running Totals) providing the formula is executed after the running totals have their values (I assume footer means report footer, or?).

And you can eliminate the whole NULL issue by selecting File->Report Options->Convert Null Field Value to Default

People use sharedvariables constantly, and they work fine.

Failures are GENERALLY either that they are expecting the result of a shared variable in the same section as the source of it, or they are resetting it in the wrong location.

-k
 
I already tried the Convert Null to Default, but with Pervasive SQL, it doesnt work, hence the extra step.

Footer means footer of the subreport.
It worked once for me and gave me the right values, but then for some reason (i know this sounds ridiculous), they reverted back to the original strange values. I heard this from someone else too.
 
Be careful about listening to the voices ;)

I've never heard that convert null values doesn't work with a database, interesting, how did you learn of this? It's surprising since it's done within Crystal, and has nothing to do with the database used. I also checked the knowledgebase and couldn't find anything.

I suspect that you have some minor oversight involved with your problem, shared vars work fine.

-k
 
you have no idea how horrible it is to use Pervasive SQL, but the client has it installed, so I have to make do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top