Solved

Crystal Report for next loop syntax issue

Posted on 2009-07-09
12
2,739 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 101

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 101

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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 101

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

728 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