Crystal Reports Formula Workshop boolean condition to string
Solution 1
Make sure your SoortKorting field has always true or false. Maybe there's a null and in that case your formula will not work.
Try with this:
if isnull({tblAankoopDetails.SoortKorting} ) then
" "
else
if {tblAankoopDetails.SoortKorting} =true
then "€" else "%"
Solution 2
Make sure there is nothing else in the same formula. Usually I see that particular error when a formula sometimes returns a string, and sometimes a number.
Also, you shouldn't need to test for true, so you might try:
if {tblAankoopDetails.SoortKorting} then "€" else "%"
Related videos on Youtube
Jay
Updated on August 13, 2020Comments
-
Jay over 3 years
I'm currently trying to create a report using Crystal Reports that comes with Visual Studio 2008.
I would like to include a field of type boolean on my report that shows a string rather than true or false. The string should contain either contain a € or a % sign.
How would I go about doing this in the Formula Workshop?
I've tried things like e.g.
if {tblAankoopDetails.SoortKorting} = true then "€" else "%"
However this never seems to work and results in warnings such as "The formula result must be a number".
This should be fairly simple but this is my first go at using Crystal Reports.
Help would be much appreciated.
Jay
-
Jay about 14 yearsAs you suggested there currently are fields containing a null. I obviously hadn't thought about catching that exception if you hadn't mentioned it. What you suggested works like a charm, even without the code preceding 'else'. I think what I did wrong was try to format edit the actual boolean text field rather than create a formula from scratch and drag that onto the report. In short, thank you very much for your swift reply including bonus suggestion :) Much appreciated!
-
Jay about 14 yearsSo you can omit 'true'? I wasn't sure whether you could do that. However, as stated below I think I was simply trying to edit the 'item' itself rather than creating a formula from scratch, my bad. Thank you for your suggestion!
-
labilbe over 2 years@Jay expression returns true. So you are doing expression = true or true = true. This is a useless equality comparison.