Adding comments to formulas

Friday 23 December 2016 @ 12:58 am

Most programming languages allow you to add comments in your code. This is useful to explain a calculation or to document changes. Creating these comments usually involves some special punctuation at the beginning and/or end of the comment which tells the program to skip over those lines.  There are several different syntax patterns that indicate comments and these vary by language.

In Crystal Reports formula syntax you insert a comment by adding two forward slashes [//] at the beginning of the comment. Crystal will ignore those slashes and also ignore anything to the right of the slashes for the rest of that line. This means you can add a comment in the middle of a line like this:

The {table.code} = 'abc' //code 'abc' is for special cases
then 'special'
else  ' '

Or you can start a line with two slashes and Crystal will ignore the entire line. In either case the commented text will turn green to show that Crystal recognizes the comment.

But one warning, I don’t recommend that you put any comments in the selection formulas (record or group). The reason is that the selection formulas can be rewritten by the select expert. Any time you use the select expert to change the criteria, Crystal will regenerate the selection formula from scratch and all the comments will disappear. So if you need to add a comment to the report criteria you can write that criteria in a separate formula field, and include the comments in that formula. Then you can use the formula field as part of the selection criteria.

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







Leave a Reply

Jeff-Net
Recrystallize Pro

Crystal Reports Server