How to use if then else to build a string in a crystal reports formula

crystal-reportssyntax

This is Crystal Reports 9 in Visual Studio 2003 by the way

Simple question about crystal reports formula syntax: How do I build the formula's result using if then clauses?

Specifically I would like something like this:

dim val as string
val = {table.level}
if {table.uom_id} = 5 then 
  val = val & ' feet'
else
  val = val $ ' meters'
end if

and val should be the result of the formula.

As long as we're at it, are there any shortcuts for writing these? These are horribly verbose, the ternary operator would be very welcome.

Best Answer

Your example is close. Just use Crystal syntax, as shown here:

stringvar val := {table.level};

if {table.uom_id} = 5 then
  val := val + ' feet'
else
  val := val + ' meters';

//to return a value, just plop it down at the end
val

But if you want something a little more concise, use this:

if {table.uom_id} = 5 then
  {table.level} + ' feet'
else
  {table.level} + ' meters';
Related Topic