Crystal Reports 2013: Formula repeating same error

73 Views Asked by At

First time trying to program with Crystal Reports. I am trying to write a simple enough one. There are different fields grouped together, and I am planning to run the formula on each group. In the below image is an example of a group.

reportImage

The highlighted 20.00 in the upper right corner of the image is the shipctns. My formula is

Local NumberVar RTotal := 0;
Local NumberVar diff := 0;
While RTotal <  {@shipctns} DO
(
 If ({@pickctns} <  {@shipctns}) AND (RTotal + {@pickctns} < {@shipctns}) THEN
    "Pick";
    RTotal := RTotal + {@pickctns};
 Else If  {@pickctns} <  {@shipctns}  THEN
    "Pick " & ({@shipctns} - RTotal);

 Else
    "Don't Pick"
); 

The formula is still a work in progress. It's just to go through the Pick Ctns in each group, and say to pick this amount to make up the shipctns amount. Only select part of the last Pick Ctns if it is too large and then stop.

My problem is that I can't really test out the formula because I am getting an error on the Else If saying "The ) is Missing". I don't really know Crystal Reports so what am I doing wrong here?

1

There are 1 best solutions below

3
On BEST ANSWER

You need to surround multiple statements within a then or else block with parentheses.

From the Crystal Reports documentation:

The correct Crystal syntax for If statements is if <condition> then <then> else <else>, where <condition>, <then>, and <else> are all single expressions. If you have multiple expressions after the <then> or <else>, convert them into single expressions by surrounding them in parentheses.

Your formula should look like this

...
If ({@pickctns} <  {@shipctns}) AND (RTotal + {@pickctns} < {@shipctns}) THEN
(
    "Pick";
    RTotal := RTotal + {@pickctns};
)
Else If  {@pickctns} <  {@shipctns}  THEN
    "Pick " & ({@shipctns} - RTotal);
Else
...