Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: IsNull doesn't completely work Post Reply Post New Topic
Author Message
SteveDLC
Newbie
Newbie
Avatar

Joined: 27 Jan 2016
Location: Australia
Online Status: Offline
Posts: 21
Quote SteveDLC Replybullet Topic: IsNull doesn't completely work
    Posted: 10 May 2016 at 7:50pm
Hi,

I've used IsNull many times and it works (mostly).

However I'm having difficulty with it when table data doesn't exist.

I have a main report and subreports which pass data back to the main report and it all works fine but sometimes I get an error in the main report stating various errors. I can see the problem is that there is no data at all. So I have deduced there is an issue with how to handle Null information on the subreports.

As an example below is a snippet of code.....

// Quantity on Hand
If IsNull ({inventory.qty_on_hand}) Then
    QoH := 0
Else
    QoH := {inventory.qty_on_hand};

For some reason this falls over when table data doesn't exist. Is there a way to force a zero in this situation?

IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 11 May 2016 at 4:03am
Is 'Default Values for Nulls' selected in the formula editor? 
IP IP Logged
SteveDLC
Newbie
Newbie
Avatar

Joined: 27 Jan 2016
Location: Australia
Online Status: Offline
Posts: 21
Quote SteveDLC Replybullet Posted: 11 May 2016 at 1:24pm
No. However, I just read the help files on this and have a better understanding of this and have now changed them all (including the default).

However I still get an error. One of the subreports which is looking for the data has just one formula as shown below.

Shared StringVar sales_hist_cy;
StringVar hist;

If IsNull({invhist.qty_sale}) Then
    hist := "0;0;0;0;0;0;0;0;0;0;0;0;0"
Else
    hist := {invhist.qty_sale};

Local NumberVar hh := Len(hist);

sales_hist_cy := Left(hist,hh-2)

The intention is to find the data and remove the last two characters on the right because I only need 12 elements.

The formulas on the main report are showing an error that states the shared variable sales_hist_cy is equal to "" (nothing). The syntax for the variables is correct. I've checked that many times to be sure.

As mentioned above, the product has no history and thus there is no entry in the table that stores the data. This is not a common occurrence but happens enough to be a problem.



Edited by SteveDLC - 11 May 2016 at 7:04pm
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 12 May 2016 at 4:18am
Sometimes I have seen that the isNull does not work well with strings (I have no idea why).  Try replacing the  If IsNull({invhist.qty_sale}) with if Len({invhist.qty_sale}) = 0.

Also I am assuming that {invhist.qty_sale} is a string value (otherwise you will get an error).
IP IP Logged
SteveDLC
Newbie
Newbie
Avatar

Joined: 27 Jan 2016
Location: Australia
Online Status: Offline
Posts: 21
Quote SteveDLC Replybullet Posted: 12 May 2016 at 7:38pm
Hi,

Looks like the 'Default Value for Nulls' along with another variable on the main report checking to see if it is indeed Null seems to work. I've tried to break it with know problem causers and so far, so good.

Thanks for your help.
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.029 seconds.