Correct syntax for multiple execution lines inside an if-else Crystal Report formula

10,095

Based on the below 2 sites I really thought you could have multiple statements inside an if-else but nothing I tried was working.

http://www.experts-exchange.com/questions/23735693/Multiple-line-IF-statement-in-Crystal-Reports.html

http://www.kenhamady.com/formulas/form08.shtml

I ended up getting this to work by restructuring my logic to be as shown below. It's a little clunky but it made the CR compiler happy.

//Syntactically correct - this worked:
//-------------------------------------
Local stringVar outputString := ""; 
stringVar array x := "";
Local numberVar i; 

If isNull({Evaluation.Strategic}) Then
   (
    x := ""
   )
Else
   (
    x := split({Evaluation.Strategic},"|");
   );

If x <> "" Then
(
    For i:=1 to Count(x) do
     (
     outputString := outputString + x[i] + Chr(10)
     )
)
else
(
For i:=1 to Count(x) do
     (
     outputString := "None";
     );
);

outputString;

Edited: And another site that suggests you can have more than one statement inside an If: https://msdn.microsoft.com/en-us/library/ms225356(v=vs.80).aspx

Share:
10,095
ingep
Author by

ingep

Updated on June 04, 2022

Comments

  • ingep
    ingep almost 2 years

    I keep getting an error "A string is required here" in my Crystal Report formula. The part that gets highlighted is the "else" portion, suggesting that is where the error is. I've tried so many different variations of brackets, no brackets, semi-colons, etc... sometimes I get a different error but none of it seems to work.

    Local stringVar outputString := ""; 
    if isNull({Evaluation.Strategic}) then
    (
     outputString := "None"
    )
    else
     (
    stringVar array x := split({Evaluation.Strategic},"|"); 
    Local numberVar i;
    For i:=1 to Count(x) do
       (
       outputString := outputString + x[i] + Chr(10)
       )
    );
    outputString;
    

    Can anyone please point out to me the correct syntax to do what I want to do? All the samples I've found online (there are few with multiple lines inside the if-else blocks) suggest this should work.

    Thanks