Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Null Value Not Passed from Sub Report to Main Post Reply Post New Topic
Author Message
skinfreak
Newbie
Newbie
Avatar

Joined: 29 Jan 2009
Online Status: Offline
Posts: 18
Quote skinfreak Replybullet Topic: Null Value Not Passed from Sub Report to Main
     Posted: 29 Jul 2009 at 5:55am
I am scratching my head like hell...

I have a main report which has a number field linked with a subreport.
//@SubFormula
//Stores the value of the {@TAT_AvTAM} field
//in a number variable called 'myTotal'

WhilePrintingRecords;
Shared NumberVar myTotal := {@TAT_AvTAM}

//@MainFormula
//Returns the value that was stored
//in the shared number variable called
//myTotal in the subreport

WhilePrintingRecords;
Shared NumberVar myTotal;
myTotal


The output is in the main correct, but there are several values in the sub report which do not exist and are present as blanks. This is intentional. I want to take these number fields and use the average function on them.

At present all null values in the sub report are being passed a zeros which will skew the average calculation. Is there any way to force the passing of null values, or is a null number field zero by definition?

Failing that, I tried using a simple IF statement to exclude all values of the passed field which should be null (there are other fields in the main report which would indicated this) but this has not worked either.

Anyone have any ideas?


Edited by skinfreak - 29 Jul 2009 at 6:01am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 29 Jul 2009 at 6:25am
I don't know about the passing null as zero (does it display in the subreport as a null or as 0?).  Crystal has the option of setting nulls to defaults, which might be happening, though as I think about it, it is probably that a numbervar cannot be NULL, so it is setting it to 0.
 
I am not sure if this will work, but it is what I would try...
Calculate the Average yourself, you would just need an accumulator and the count.  Now this won't change the results...yet.  What if you changed the numbervar to a stringvar and...
 
Shared StringVar myTotal;
if ISNULL({@TAT_AvTAM}) then
 myTotal :=""
else
 myTotal := {@TAT_AvTAM}
 
Now in your main report you could do something like:
shared numbervar totCount;
shared numbervar totAmount;
shared stringvar myTotal;
if myTotal <> "" then (
 totCount := totCount +1;
 totAmount := totAmount + VAL(myTotal)
)
 
just a thought...
Hope it helps
IP IP Logged
skinfreak
Newbie
Newbie
Avatar

Joined: 29 Jan 2009
Online Status: Offline
Posts: 18
Quote skinfreak Replybullet Posted: 29 Jul 2009 at 6:58am
Unfortunately that did not work - {@TAT_AvTAM} is a number field nad crystal errors that it requires a number. If I sub the myTotal :="" for myTotal :=0 it's fine.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 30 Jul 2009 at 10:53am

sorry, you need to convert the nubmer to a string

so replace:myTotal := {@TAT_AvTAM}
with:
myTotal := totext({@TAT_AvTAM},0,"")
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum