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

Need Help With For Loop Function

Status
Not open for further replies.

zxmaximus

Programmer
Nov 22, 2004
3
GB
Hi There,

What I am trying to do is loop through a number of records and exit the loop when the quantity is equal or greater than the running total. But the thing is I also want to include the first field that it comes across that satisfies the criteria.

Here is an example:

Quantity A Quantity B Running Total(B)
========== ========== ================
1000 50 50
2000 100 150
3500 550 750
5000 400 1150
6500
7000

In the example above I want to only display the records in B when the running total meets or exceeds quantity A

 
How is the running total computed? How do you know when

You can't use a loop to go through a subset of rows in Crystal.

Your post contradicts itself, you state "But the thing is I also want to include the first field that it comes across that satisfies the criteria."

and then state "I want to only display the records in B when the running total meets or exceeds quantity A"

One says only the first row, the second states records above the qty in A, which is it?

Create a Running Total field to sum the Quantity B field.

Place it in the details alongside the Quantity A and Quantity B fields.

Rght click the details and select Format Section and in the X 2 next to suppression place:

{#MyRunningTotal} < {table.QtyA}

-k
 
Hi There k,

Sorry about that. I'll try to explain. Every Qty in Qty B column represents a transaction in a table. The running total is adding each transaction qty every record that it goes through.
Now what I want is to only show the records up until the running total is greater than or equal to Qty A. All other records I do not want to show after that point.

Does this make more sense?
 
Up until the running total is greater, OK, do the same thing but change th formula to:

{#MyRunningTotal} > {table.QtyA}

-k
 
Thanks K but the problem is I need to ALSO include the first record that is greater, as this will be the qty I need
 
OK, create a formula such as:

booleanvar Bigger;
if {#MyRunningTotal} > {table.QtyA} then
Bigger:=True

Right click the details and place this formula in the details B section and hide or shrink it.

For the suppression of Details A use:

booleanvar Bigger

You'll see those smaller and the first one larger than QTY A

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top