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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use global variable? 2

Status
Not open for further replies.

jamor1999

Technical User
Jun 26, 2001
182
US
Hi everyone,

I just started playing with Crystal and variables and I think I'm missing some information.

I have several formulas in my report. One declares and assigns an initial value to a variable I called A. In the second formula, I need to manipulate the value of A and assign it to variable B.

The problem is, in the second formula, when I say A := A + B;

I get an error as if Crystal wants me to declare A. If I do declare A a second time, it goes through w/out an error. Am I missing something? Is there a particular way to reference a global variable when working in different formulas???
 
By the way, I forgot to mention, of course if declare A a second time I've lost the data that I wanted to store from formula one in the variable A.

Can anyone help?
 
You must always reference a variable prior to using it in a formula.

Here's an example:

Group header formula
whileprintingrecords;
numbervar Countem := 0;

Detail level formula
whileprintingrecords;
numbervar Countem := Countem +1;

Group footer formula
whileprintingrecords;
numbervar Countem

This will display at the group footer, reset at the group header, and accumulate at the group footer.

If you use a variable across a subreport, declare it as shared, as in:

whileprintingrecords;
shared numbervar Countem

By default variables are global, to reference one just for it's current formula, you can use Private.

Hope this helps to explain this. I'd guess that you were setting a value for the variable in the formula where you'd intended to accumulate.

If you have additional problems, please post where in the report, and what is in these formulas, rather than an example.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top