views:

55

answers:

2

I've written a formula as follows

whileprintingrecords;

shared numbervar level1;

level1:=level1+1;

ToText(level1,0);

And placed it into a report as so:

Report Header a |   {formula} {Text:Introduction}
 Report Header b |   {formula} {Text: Scope} 
 Report Header c |   {formula} {Text: Overview} 
 Group Header a |   {formula} {Group Header text}

The print result is

1 Introduction
1 Scope
1 Overview
2 Group Header text

I would expect to see

1 Introduction 
2 Scope 
3 Overview 
4 Group Header text

It seems the formula is being evaluated once for the entire Report Header sections and the single result is being printed everyone the formula is placed. Is there any way to force evaluation of the formula each time it appears in the report, and not rely on some cached value?

Of course, alternative implementation suggestions welcomed too.

Thanks in advance,

Shamrock

+1  A: 

Options:

  1. You can get creative with Running Total formulae.

  2. If you're not suppressing groups, you could also try GroupNumber+3 as your formula, but that can get confusing when you factor in sorting, suppression, etc.

  3. If there's only 3 Report Header subsections, then I'd recommend just hard-coding it in there. Add 1 more line to your code:

    whileprintingrecords;
    shared numbervar level1;
    if level1=0 then level1:=3;
    level1:=level1+1;
    totext(level1,0);

    I recommend this one.

PowerUser
No, I haven't tried that. I'll look into it. Thanks.
shamrockva
Actually, see my Edits. I can't immediately think of a way to reevaluate a formula every time it is displayed, but in your example problem, this should be just as good.
PowerUser
Thanks for the suggestions, but #3 just returns 4 4 4 instead of 1 1 1 when the formula is placed in the same section 3 times. The general question is how to get a formula to print a different value each time it is placed in a report, even within a single section.
shamrockva
Your general question is difficult to answer because Crystal thinks in terms of records, not subsections. Can you give us the bigger picture of what you're trying to do? If you're willing to put in the time, maybe you could do something with shared variables and subreports.
PowerUser
A: 

Since the report header section only happens once per report, don't include the formula in the header section - instead, hard-code (ie. include as text) the numbers 1, 2 and 3 for the three report header sub-sections. Include the formula in the Group Header only, modified to read as follows:

whileprintingrecords;

shared numbervar level1;

level1:=level1+1;

ToText(level1+3,0);

Like so:

Report Header a |   1 {Text:Introduction}
 Report Header b |   2 {Text: Scope} 
 Report Header c |   3 {Text: Overview} 
 Group Header a |   {formula} {Group Header text}
Mark Bannister