Solved

Crystal Report for next loop syntax issue

Posted on 2009-07-09
12
2,712 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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 35

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
 

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 35

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 35

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 35

Expert Comment

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

 James
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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