Joined: 08 Aug 2012
Online Status: Offline
Posts: 2
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 )
Joined: 08 Aug 2012
Online Status: Offline
Posts: 2
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
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
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