Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Returning null (invalid ) value from formula Post Reply Post New Topic
Author Message
Sir Clive
Newbie
Newbie


Joined: 08 Aug 2012
Online Status: Offline
Posts: 2
Quote Sir Clive Replybullet Topic: Returning null (invalid ) value from formula
     Posted: 08 Aug 2012 at 10:16pm
Hi all

First post so apologies if this has been answered before , I did search but couldn't find anything suitable.

I have 2 Number values 'totalPrice' and 'pricePerUnit' which are calculated in formulae

I need to calculate a result in another formula as follows

amount = totalPrice / pricePerUnit.
I want to display a string representation of this amount, but I also want to display 'N/A' in certain circumstances

I have a formula for all 3 of these - @totalPrice and @pricePerunit return NumberVar. @amount returns a string

totalPrice may be 0.0 in which case amount will be 0.0 - I can easily handle that in the amount formula

pricePerUnit may be 0.0 or invalid in which case amount will be N/A - again easily handled

But if @totalPrice is invalid ( rather than 0.0 )  I also want to display N/A for the amount. In C# / Java this is easily handled by @totalPrice returning null rather than 0.0

But here I have had to kluge by having @totalPrice either convert to a string , then @amount convert it back again, or @totalPrice returning some unlikely ( but not impossible ) value back ( e.g. -1234567.89 )

Is there a neater way of doing this ?

Thanks


IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 09 Aug 2012 at 3:57am
can you explained how you are defining or what constitutes an 'invalid' @totalprice

Edited by DBlank - 09 Aug 2012 at 3:57am
IP IP Logged
Sir Clive
Newbie
Newbie


Joined: 08 Aug 2012
Online Status: Offline
Posts: 2
Quote Sir Clive Replybullet Posted: 10 Aug 2012 at 5:41am
Thanks for the reply

It's where I check a number of conditions in other ( boolean returning ) formulae to set the value but it is possible that none of the conditions were satisfied and I need to know this in the calling function

e.g (  code untested )

local NumberVar priceValue := -9999.99;

//test 1
If  {@Condition1} AND {@Condition2} Then
(
    priceValue := {SomeReport.someField};
);

//test 2
If  {@Condition3} AND {@Condition4} Then
(
    priceValue := {SomeReport.someOtherField};
);

// I need to detect in the calling formula that none of the conditions were met
// but a value of -9999.99 might have been legitimately assigned as a result of test 1 or test 2

priceValue;

--------------------------------------------------------------------------------------

I guess I could have another formula which returns a boolean based on whether at least one of the conditions were met and call that first, then only call this fucntion if that  but this seems a bit messy

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