Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to clear a variable

Status
Not open for further replies.

henky

Programmer
Jul 20, 2000
56
NL
Hi guys and girls,

I use CR 8.5 prof

my formula is: (standing in group #2)
------
numbervar week1;

if GroupName ({@days old}) = "week1" then week1 := DistinctCount ({database.field}, {@days old});
------
I have a variable "week1" and I use "week1" in group #2 and I call the variable in group #1. It works good WHEN I have only 1 time a group #1.

Now I have 5 times Group #1 in my report. So I use the formula 5 times. It works perfect expect when I have no data in group 2. When I have no data in group #2 and the report does call the variable, it shows the amount of the group #2 before.

I hope it is clear, when not, please aske what isnt clear, so I can tell you.

Greetz,
Henky
 
I am not sure what you are trying to do but the following will explain how to use variables to conditionally increment a variable for each detail line and display it in the group footer. The variable is initialised to zero for each new group. Hope it helps.

1. In the group header, create a formula called Variable_Init. This initialises the variable each time the Group name changes.

The formula should only contain

Shared NumberVar variablename := 0;

2. In the data line create a formula called Variable_calculation. This will conditionally increment the value of the variable.

The formula should contain something like

Shared Numbervar variablename;

If condition = TRUE
then
Variablename := variablename + 1
else
Variablename := Variablename

3. In the Group footer create a formula called Variable_display. This will display the current value of the variable.

The formula should read

Shared NumberVar variablename;

variablename
 
A couple of things re the previous post

If should be "Global" - not "shared" - you only need shared variables to share between a subreport and main report.

And set an evaluation time - so the start of all your formulas should be
WhilePrintingRecords;
 
Hi.

I don't understand what your are trying to tell me. Can you explain it to me again?

Henky
 
I think that the reason it displays the previous value is that the variable is not initialised in the group header.

If initialised, it will start to be recalculated/evaluated every time the group changes.

In my example the three variables allow this to happen.

Another thing to note is that unless you define your variable as Global or shared, the 3 formula scenario described in my earlier posting will not work.

Hope this helps.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top