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 Currency Variables and Nulls

Status
Not open for further replies.

Dross

Programmer
Aug 16, 2001
212
US
I am using sub reports and passing info using Shared Currency Variables. When I do a grand total I want to check to see if any are null. I am using:
shared CurrencyVar x;
shared CurrencyVar y;
if isnull (x) then
y
else if isnull (y) then
x
else
x-y
It won't let me check the variable for a null value. It wants a field. Is there any way around this?
 
You could always assign your currency variables a zero when the data field is null (from the main report). Then your sub-report could drop the IF isnull test altogether.

//MAIN REPORT//
shared CurrencyVar x;
shared CurrencyVar y;

If isnull({my.data.x}) then
x := 0 else
x := {my.data};
If isnull({my.data.y}) then
y := 0 else
y := {my.data.y};


//SUB REPORT//
shared CurrencyVar x;
shared CurrencyVar y;
if x = 0 then
y
else if y = 0 then
x
else
x-y

Shouldn't that work?

James
 
I'm new at shared variables and I think my issue is along the same lines as this.

I have three subreports, and I want to total the three subreport values in the main report. It works fine until one of the values isnull (it just grabs the value from the previous record). I'm assuming null is not a valid value to pass to the main report.

Is that a way around this?
 
I did get it to work by creating a formula called amount and put:
if {table.field} = 0 or isnull ({table.field}then 0
else
{table.field}

and then in the shared variable I put:
shared CurrencyVar x;
x:=0;
x:=Sum ({@Amount});

This way it converts a null to 0 and resets each time. Now you can just declare the shared variables in the main report and do the math.

Hope this helps.
 
I'm running into another issue. When I run the report without suppresssing the subreport, my calculation in the main report (subreport1-subreport2) works fine. But when I suppress the section to hide the subreports my shared variables return only 0. Is this because my main report shared variable formula is a whileprinting records as below?

WhilePrintingRecords;
Shared NumberVar x;
x
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top