Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

For loop in Crystal reports - printing issue

Posted on 2009-06-30
2
Medium Priority
?
1,473 Views
Last Modified: 2012-05-07
Hi,

I have a formula field, in basic syntax, that uses a for loop.  The contents of the formula section should be printed the number of times as (i), the number of times it loops.

However, it loops 5, and only prints the last one?

Here is my code:
Dim i As number
Dim dval As Double
Dim deprec As Double
Dim d_cost as double
dim i_term as number

d_cost = {ITEMUNITOFMEASURE.UnitCost}
i_term = {ITEMUNITOFMEASURE.Lifespan}

dval = d_cost
For i = 1 To i_term
            deprec = d_cost / CDbl(i_term)
            dval = dval - deprec
Next i        
formula = "End of Year" &  i  & " Depreciation:" & deprec & "Current Value:" & dval


Here is the output:
End of Year5.00 Depreciation: 2,189.72 Current Value:240.88

The output that I want is:
End of Year1.00 Depreciation: 2,189.72 Current Value:8,999.76
End of Year2.00 Depreciation: 2,189.72 Current Value:6,810.04
End of Year3.00 Depreciation: 2,189.72 Current Value:4,620.32
End of Year4.00 Depreciation: 2,189.72 Current Value:2,430.60
End of Year5.00 Depreciation: 2,189.72 Current Value:240.88

Thank you.
0
Comment
Question by:Lalla Belle
2 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 total points
ID: 24743966
your 'formula= ' command is outside of the loop so you will only get the last value.
you need a
Dim Result as string

plus...


For i = 1 To i_term
            deprec = d_cost / CDbl(i_term)
            dval = dval - deprec
              result = result & "End of Year" &  i  & " Depreciation:" & deprec & "Current Value:" & dval & chr(13)
Next i        
formula = result
0
 

Author Closing Comment

by:Lalla Belle
ID: 31598284
Thank you it worked perfectly!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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. …
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses

927 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