The ) is missing ?!?

Saturday 27 December 2014 @ 12:32 am

If you make a mistake in a Crystal Reports formula, the error messages are usually pretty helpful. But every once in a while the error can send you on a wild goose chase. The message above is a good example. It will appear when you have an opening paren without a closing paren. But it will also appear in the following formula, even when the parens match:

NumberVar Save01;
NumberVar Save02;
NumberVar Save03;

if {@criteria}
then (Save1 := 0; Save02 := 0; Save03 := 0)

Now in this formula it is obvious that the parens are not the problem. So why would the error message mention a missing paren? This happens only when you have a specific combination of factors – a bad variable name within a pair of parens.  If you misspell a variable name that is NOT within parens, you will get an error message that says “the following text does not appear to be part of the formula”.  If you misspell a field name (with or without parens)  you would get an error about the field name. Most syntax errors generate the same syntax warning inside or outside of parens. But if you misspell a variable AND it happens within a pair of parens, then CR warns you about a missing paren even if it is NOT missing.

In a simple formulas like the one above it doesn’t take long to realize that the error message is a red herring. But with a more complex formula you might spend quite a bit of time checking parens before you realize that the problem lies elsewhere.  I know from experience.  This happened to me twice in one week with two different customers, which is why noticed the behavior.

The good news is that when the error pops up there is a clue that tells you if the problem is really a missing paren or a bad variable. When the problem is really a bad variable name then the cursor will move to highlight the name of the problem variable. When the problem is a missing paren then CR will not move the cursor.

(For examples of my most popular formulas, please visit the FORMULAS page on my website.)

Leave a Reply

Recrystallize Pro

Crystal Reports Server