views:

9458

answers:

2

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.

+1  A: 

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';
JosephStyons
Thanks, these are a total pain
George Mauer
Yes they are. If Crystal allowed you to call one function from another (w/parameters), life would be so much easier.
JosephStyons
Actually, I think Crystal _does_ allow you to call a function from a formula.
SarekOfVulcan
You can call another *Crystal* function, but you can't pass them any arguments.
JosephStyons
A: 

Local CurrencyVar percentage:=0 Local CurrencyVar percentage1 := {Query1.Expr1000}*{File_Master.Percentage}/100 if {File_Master.Above_Below}= "ABOVE" then percentage:= {Query1.Expr1000}+percentage1 else percentage2:= {Query1.Expr1000}-percentage1;

its shows error " The remaining Text does not appear to ve part of the formula". send me reply on [email protected]

Harshad