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

Use of variables 1

Status
Not open for further replies.

BillPeck

Programmer
Feb 25, 2004
18
US
I'm trying to do some basics with variables and not having any luck.

I'm just trying to count the # of USA customers, like this:

FORMULA FIELD:
numberVar USA_Total_Customers := 0;

whilePrintingRecords;
If {Customer.Country}="USA" then USA_Total_Customers := USA_Total_Customers + 1

Then I display the formula in the report footer. But it shows 0.

The detail records are displayed.

Thanks.


Bill
 
Try creating a formula that evaluates each record like this:
Code:
If {Customer.Country}="USA" then
    1
else
    0
Place it in your detail section.
Suppress it if necessary.
Right click the field, and choose Insert, Grand Total.
Make sure that it is a Sum.
Click OK.
It will be added to your Report Footer.

~Brian
 
Brian,

hi, thanks for the tip. I have done the formula and summary field (as you suggested) and was just trying to get a feel for variables and how they work using a simple example.

Any thought on what I'm doing wrong with the variable?

Thanks.

Bill
 
The problem lies in that you are trying to increment and display the variable in the same formula. The formula is only getting executed once based upon where it resides, the report footer.

Try splitting it into three formula; one to initialize, one to increment, and one to display.

You should do somehting like this:

@Initialize
Code:
whileprintingrecords;
numberVar USA_Total_Customers := 0;
Place formula in the report header and suppress.

@Increment
Code:
whileprintingrecords;
numberVar USA_Total_Customers;

If {Customer.Country}="USA" then
    USA_Total_Customers := USA_Total_Customers + 1;
Place formula in the details section and suppress.


@Display
Code:
whileprintingrecords;
numberVar USA_Total_Customers;
Place formula in the report footer.


~Brian
 
1 did you put your formula field in the report (detail) otherwise maybe it will not calculate the value
2 you say you display the formula in the RF
To display the variable, you need to have another formula field
@result
whileprintingrecords;
numbervar USA_Total_Customers;
USA_Total_Customers

then you put it in the RF

--------------------------------------------------
[highlight]Django[/highlight] [thumbsup]
bug exterminator
tips'n tricks addict
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top