Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 489
George Mauer Avatar asked Nov 20 '08 21:11

George Mauer


1 Answers

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';
like image 63
JosephStyons Avatar answered Oct 21 '22 15:10

JosephStyons