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

Counting Variables

Status
Not open for further replies.

ScottWood

Technical User
May 31, 2001
81
0
0
GB
I have a report that looks at stock information, on the right hand side i have the product, then i have a variable for each branch, these are contained in the detail section, i have then grouped on the product feild, and created a subtotal for each branch.

GH1: Product SumBranch21 SumBranch22 SumBranch23
Detail: Product Branch21 Branch22 Branch23

Ive created a count feild in GH1 with a formula as follows

NumberVar Count;

If (@SumBranch21)=0 then
Count:=Count+1 else
If (@SumBranch22)=0 then
Count:=Count+1 else
If (@SumBranch23)=0 then
Count:=Count+1

There are no errors in the formula as far as i can tell, but if there are any 0's in the SumBrach?? fields it will only increment the counter once regarless if there are 2 or 3 0's.

Is this possible?
 
If you're using Crystal 8.5, Running Totals should be easier and more flexible.

Madawc Williams
East Anglia, Great Britain
 
I am using 8.5, but i cannot just use a running total, to look through the subtotals, and increment the counter by 1 if there is a zero in there.

thanks
 
If you are wanting to check to see if a total is zero,
you may need to put whileprintingrecords; as the first line of your numbervar count formula.

If not, the report may be only counting the last one.
 
Your formula basically says that if ANY of {@sumbranch??} = 0 then count 1, and it appears that the formula is doing that. Once a condition of the formula is satisfied, the then statement is executed, but it doesn't keep looping through the other sums then.

Is it that you want to count how many of the {@sumbranch??} = 0 per group?

You might want to try something like the following, if that is your goal:

whileprintingrecords;
Numbervar Count;

If {@SumBranch21}+{@SumBranch22}+{@SumBranch23}=0 then
Count:=Count+3 else
If ({@SumBranch21}+{@SumBranch22} = 0 or
{@sumBranch21}+{@SumBranch23}=0 or
{@SumBranch22}+{@SumBranch23} = 0) then
Count:=Count+2 else
if ({@SumBranch21} = 0 or
{@SumBranch22} = 0 or
{@SumBranch23}=0) then
Count := count + 1;

-LB
 
Let me amend that formula slightly, since "count" is a reserved word, and to allow for the running total to be maintained when no criteria are met:

whileprintingrecords;
Numbervar Counter;

If {@SumBranch21}+{@SumBranch22}+{@SumBranch23}=0 then
Counter:=Counter+3 else
If ({@SumBranch21}+{@SumBranch22} = 0 or
{@sumBranch21}+{@SumBranch23}=0 or
{@SumBranch22}+{@SumBranch23} = 0) then
Counter:=Counter+2 else
if ({@SumBranch21} = 0 or
{@SumBranch22} = 0 or
{@SumBranch23}=0) then
Counter := counter + 1 else
counter := counter;

This now tests out, but we still haven't heard back whether my guess is accurate about what you were trying to do.

-LB
 
Hiya,

Thanks for the help, but its not quite what i need to do, im not adding the {@SumBranch} feilds together, i have a list of these {@Sumbranch} feilds in the GH, and i have a counter in the header, what i want the counter to do, is look at the {@SumBranch} Feilds and if any of them are 0 then to increment the counter by one. At the moment all it is doing is looking through the {@SumBranch} feild, if it sees a 0 it then increments the counter by 1, but them it stops and doest look at the rest.

Thanks
 
When you say it stops and doesn't look at the rest, do you mean that it only increments for the first product and then not for subsequent products?

If this is the case try the following:
whileprintingrecords;
NumberVar Counter;

If (@SumBranch21)=0 then
Counter:=Counter+1 else
If (@SumBranch22)=0 then
Counter:=Counter+1 else
If (@SumBranch23)=0 then
Counter:=Counter+1 else
counter := counter;

The final clause will maintain the value when the condition is not true.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top