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
Solved

For loop in Crystal reports - printing issue

Posted on 2009-06-30
2
1,446 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 500 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: 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

Suggested Solutions

Title # Comments Views Activity
C# Crystal Reports 15 93
Crystal Reports total formula with groups? 4 56
How to create code39 alphanumeric barcodes in  Crystal Reports? 10 76
Crystal Reports Version 7 4 33
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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