We help IT Professionals succeed at work.

Crystal Reports - Formulas in detail section

Yeturi
Yeturi asked
on
Hi,

I have a gloabal variable x declared in a formula. I increment that field by 10.

My requirement is like below: I want to place the same formula in Page header and Detailed section. data in detailed section is not being repeated as I used the same formula.
Requirement:
Page header:
Display Value of x as 10.

Detail section: display as below.
20
30
40

Displaying as:
Page header:
10

Details Section:
20
20
20


Could you please help me how can I get the value in formula to increment when placed in detailed section?

Thanks,
Yeturi.
Comment
Watch Question

Your formula should look something like:

Shared NumberVar x := x + 10;
x;

This will increment x by 10 and then display the new value of x.

Author

Commented:
I did the same.

WhilePrintingRecords;
Shared numbervar count1;
count1 := count1 + 10;

I placed the formula variable two times in the Detailed section as below:

@Numdisp
@Numdisp

The output displayed as
10
10

I am expecting
10
20
Senior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:
You have to put it in a separate detail section or have a second formula

Crystal caches formula evaluations and knows thaqt it evaluated the formula already so just repeats the result

mlmcc

Author

Commented:
Is there is any way, that within the same details section I can use one formula?

My requirement is like I cant have multiple detailed sections ans I need output like

10
20
30

Or else is there is any way, that I can have a counter that can be incremented in the same detailed section in a formula?
You may need to use the WhileReadingRecords evaluation runtime in order to have the formula properly increment within the detail section.

Author

Commented:
WhileReadingRecords;
Global numbervar count1;
count1 := count1 + 1;

I have rewritten the formula as above. But changed count1 from Shared to Global as it said Reading cant be with Shared.

But it dint work.. give as same..

10
10
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
Shared is intended for use with a subreport.  Global is for use within a single report.

Since subreports evaluate in the Printing Pass through the report shared variables are only valid in that pass.

I have never had a reason to update a variable as you want so I don't know if there is a way to do it.

What is the reason for doing this?

mlmcc

Author

Commented:
In my details section, I have a requirement like I need to have the label to increment with alphabets. I thought to use a sigle formula as I dont know in each details section how many times I will require the below.

So I have taken an array and trying to increment the counter by 1 but I am repeting the formula in teh same detailed section its not being incremented.

Is there is any way to acheive it?

like,

a
b
c
d
e
and so on..
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
The detail section only works on 1 record at a time.
DO you have a field you are trying to split into several lines each of which needs a "label"

mlmcc

Author

Commented:
Not sure of the question you are asking..

I have some 10 details section in the report. I will supress and enable the detailed sections based on the logic. not all the detailed sections will be invoked everytime.
The exact requirement is,, In the below, the labels for a,b,c,d,e,f,g,.. should be dynamically enabled.

Like If the logic says to display section 1 and 3 then section1 should show labels as a,b and section 3 should show as c, d.
if the logic say to display section 2,3 then labels should be as a,b,c in section 2 and d,e in section3.

Hope this is clear now. Is there is any way to acheive it?

Detailed section1:
Name           a       Datavalue
Empnum      b       Datavalue


Detailed section2:
State          c       Datavalue
Depnum    d       Datavalue
Depname  e      DataValue


Dtailed section3:
sal       f     Datavalue
Comm g    Datavalue
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:
There is but it requires you to use a separate formula for each value.
Since you are suppressing some of the sections the formulas will have account for the suppression and not increment when the section is suppressed.

I can think of a way to do this with arrays but it might not work in your case with the suppressing of sections

mlmcc