Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

For loop in Crystal reports - printing issue

Posted on 2009-06-30
2
Medium Priority
?
1,466 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
[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
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

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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

718 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