Solved

Crystal Report for next loop syntax issue

Posted on 2009-07-09
12
2,621 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:chrislindsay
  • 5
  • 4
  • 3
12 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 24814478
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
 

Author Comment

by:chrislindsay
ID: 24814670
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
 
LVL 100

Expert Comment

by:mlmcc
ID: 24815059
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
 

Author Comment

by:chrislindsay
ID: 24815214
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
 
LVL 100

Expert Comment

by:mlmcc
ID: 24815287
Not really.

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

mlmcc
0
 
LVL 34

Accepted Solution

by:
James0628 earned 500 total points
ID: 24830384
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Closing Comment

by:chrislindsay
ID: 31601584
Already thought of creating a dummy table in Sql but was really looking for a more elegant approach.  Thanks for your asisstance guys
0
 
LVL 34

Expert Comment

by:James0628
ID: 24839878
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
 

Author Comment

by:chrislindsay
ID: 24839975
Thanks James thats useful infomation.
0
 
LVL 34

Expert Comment

by:James0628
ID: 24848174
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
 

Author Comment

by:chrislindsay
ID: 24857607
Thanks James.
I have overcome this issue and have a nice loop, and have another which I have just published.
Thanks again
0
 
LVL 34

Expert Comment

by:James0628
ID: 24858397
No problem, again.  :-)  Glad you were able to work it out.

 James
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now