0
votes

Is it possible to use the name of a Crystal Reports formula inside the formula itself (in Crystal 8.5)?

For example, assume I have formulas such as:

@MOISTURE
@PROTEIN
@ACIDITY
@PROPERTYX
@PROPERTYY
@PROPERTYZ

and that the logic for each formula is identical. The only difference between the formulas is the name of the field they ultimately access. For exmaple, @MOISTURE looks like this:

if ... then {VIEW_SPECS.SOURCE_1_MOISTURE}
if ... then {VIEW_SPECS.SOURCE_2_MOISTURE}
if ... then {VIEW_SPECS.SOURCE_3_MOISTURE}
if ... then {VIEW_SPECS.AVERAGE_MOISTURE}

and @PROTEIN looks like this:

if ... then {VIEW_SPECS.SOURCE_1_PROTEIN}
if ... then {VIEW_SPECS.SOURCE_2_PROTEIN}
if ... then {VIEW_SPECS.SOURCE_3_PROTEIN}
if ... then {VIEW_SPECS.AVERAGE_PROTEIN}

Instead of typing out all this repetetive stuff for each formula, can I get the name of the formula in the formula itself, so that each formula would look something like this:

if ... then {VIEW_SPECS.SOURCE_1_{$this}}
if ... then {VIEW_SPECS.SOURCE_2_{$this}}
if ... then {VIEW_SPECS.SOURCE_3_{$this}}
if ... then {VIEW_SPECS.AVERAGE_{$this}}

I want to be able to write the formula once, and paste it into the Formula Editor for each of the formulas, without having to modify each one.

1

1 Answers

1
votes

As far as I know in Crystal a formula can't reference itself. Crystal will always throw you an error. What you can do is store values in your formulas and then reference them in another formula. So you could create Moisture1, Moisture2, etc. and then reference those. It's kind of the same but in my opinion a little less writing and better from a maintenance standpoint. If any of the sources ever change you will have to go through all the formulas and change it, whereas if you have the values stored in a formula you only have to change one formula.

EXAMPLE:

@Moisture1 formula would have the following code in it:

{VIEW_SPECS.SOURCE_1_MOISTURE}

Your other formula that is checking for the condition (if/else) would look something like this:

if......then {@Moisture1}
if......then {@Moisture2}

...and so on.