Crystal Report for next loop syntax issue

Hi Experts,
I have a report which I would like to use a variable, up to a required maximum which is a field value in my database.
I want to use the value (i)  to multiple incrementally in a group footer.
I'm not sure how to define the local variable and where to put it once I have defined it

The correct syntax would be greatly received!
Thanks


for i = 1 to (max_capacity)
 
next x

Open in new window

chrislindsayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
THe loop in your idea will execute fully each time the group footer is displayed.

I think what you want is this

In the report header add a formula
WhilePrintingRecords;
Global NumberVar i;
i := 1;
''

In the groupfooter
WhilePrintingRecords;
Global NumberVar i;
i := i + 1;

mlmcc
0
chrislindsayAuthor Commented:
Hi Thanks for the reply but I really want a limit of i = 1 to max where max is a value in a table.
When I complete the group calculation, I would like to increase i + 1 until I reach the max value and the report would loop again until max was reached

Thanks

0
mlmccCommented:
The report goes through records one at a time.  There is no way to loop again?

What are you trying to do with this?
Are you trying to get a record to display several times?

mlmcc
0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

chrislindsayAuthor Commented:
The report looks at a formule and uses the value 1 (i)  in the calculation (multiple places) (loop i+1)
the report looks at the same formule but uses the value 2 at (loopi +1)
until maxvalue.
I will return approx 200 lines (from my data) of different results as I will use i as a group below the group I am summarising)

Is this any clearer?  Thanks

Chris
0
mlmccCommented:
Not really.

Can you show a sample data and where the values would be used?

mlmcc
0
James0628Commented:
A for loop will be put in a formula and the entire loop will be executed every time the formula is evaluated.  For example, if you create a formula like the following and put it on the report (any section), every time that formula is evaluated, you will get 300, the value from the last iteration of the for loop:

Local NumberVar i;
Local NumberVar k;

for i := 1 to 10
do
  k := i * 30;

k



 It sounds like you want to do some calculations on some fields/totals/whatever in a group footer, then repeat that group footer section X number of times, with changes in the calculations.  CR simply has no way to programmatically repeat a section a variable number of times (eg. in a loop).

 There are various ways that you might be able to do what you need, depending on exactly what you're trying to do.

 A simple brute force approach would be to actually create multiple group footer sections (rather than trying to repeat them in a loop), up to however many you might need (the largest maximum value you might have in your data).

 Towards the other end of the "complexity" scale would be a subreport that reads some "dummy" datasource with as many records as the largest maximum you could have and does your calculations in the detail section, doing a new set of calculations for each record read.

 James
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chrislindsayAuthor Commented:
Already thought of creating a dummy table in Sql but was really looking for a more elegant approach.  Thanks for your asisstance guys
0
James0628Commented:
FWIW, you don't necessarily have to create a new table for this.  Basically, you just need a table with at least as many rows as you'll need iterations for your calculations.  But there are a couple of caveats.

 1) Ideally, the table would include record numbers, so you could use the record selection to control how many records the subreport reads (record_number_field <= max_capacity).

 2) Without a record number field, you'll have to use suppression, which means that CR will read every record and just not show the "extras", so you'd look for some table (or group of records within a table) that had as many records as you'd ever need, but not much more, to try to minimize the reading of unnecessary records.  For example, if max_capacity will never exceed 100, a 10,000 record table is probably not a great solution.  :-)

 James
0
chrislindsayAuthor Commented:
Thanks James thats useful infomation.
0
James0628Commented:
No problem.

 I should explain that my point in # 1 was that if you have a record number field that you can check in the record selection, that test will hopefully be passed to the server, so the server only sends the required number of records.  I just realized that I hadn't explained why you'd want to have a record number field and check it in the record selection.

 James
0
chrislindsayAuthor Commented:
Thanks James.
I have overcome this issue and have a nice loop, and have another which I have just published.
Thanks again
0
James0628Commented:
No problem, again.  :-)  Glad you were able to work it out.

 James
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.