# For Next Loop in money amounts

Hello all again... New to VB and having to write some more code for the older system at work. This one has whacked me hard.

I Need a program that is windows based and on a button click is going to calculate  intrest and compound interest. based off the amount original put in.

i.e. When \$1000 is invested at %5 simple interest, the amount grows by \$50 each year. When money is invested at 5% interest compounded annually, the amount at the end of each year is 1.05 times the amount at the beginning of that year. I need to Display the amounts for 9 years for a \$1000 investment at %5 simple and Compound interest

year     AmountSimpleIntrest  AmountCompundIntrest
1               \$1,050.00                       \$1,050.00
2.              \$1,100.00                       \$1,102.50
etc... for a total of 9 years. I need to do this on a button click on a windows form... any one have any idea how to do this?? Thank you in advance..
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
I have programmed mainly in C# and Java, but this seems to be an easy programming challenge. To display the result you may use a DataGrid or a similar control. In order to display 9 rows with the required information, simple and compound, you may write something like this (i'm thinking up instructions, this is just to give u the general idea)

``````int i=0;
grid.rows[0].AmountSimpleInterest=1000;
grid.rows[0].AmountCompoundInterest=1000;
while (i<10){
grid.rows[i].AmountSimpleInterest=grid.rows[i].AmountSimpleInterest+50;
grid.rows[i].AmountCompoundInterest=grid.rows[i].AmountCompoundInterest*1.05;
i++;
}
``````
0
Commented:
Here's my shot at it.
``````Public Class InterestCalculator

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.TextBox1.Text = "" Then
MsgBox("Enter a value")
Else
Calculate(Me.TextBox1.Text)
End If
End Sub

Private Sub Calculate(ByVal amount As String)
Dim amountInt As Integer = Convert.ToInt32(amount)
Me.TextBox2.Text = "Simple 5%   Compound 5%" & vbCrLf
Dim simple As Integer = amountInt
Dim compound As Integer = amountInt
Dim compTemp As Integer = 0
For i As Integer = 0 To 8
simple += 50
compTemp = compound * 0.05
compound += compTemp
Me.TextBox2.Text &= simple.ToString() & "           " & compound.ToString() & vbCrLf
compTemp = 0
Next
End Sub
End Class
``````
interestCalculator.jpg
0
Author Commented:
TommyBoy thats great I need it to display the years before the intrest ammounts
0
Commented:
No problem.
``````Private Sub Calculate(ByVal amount As String)
Dim amountInt As Integer = Convert.ToInt32(amount)
Me.TextBox2.Text = "      Simple 5%   Compound 5%" & vbCrLf
Dim simple As Integer = amountInt
Dim compound As Integer = amountInt
Dim compTemp As Integer = 0
For i As Integer = 1 To 9
simple += 50
compTemp = compound * 0.05
compound += compTemp
Me.TextBox2.Text &= i & ".   " & simple.ToString() & "           " & compound.ToString() & vbCrLf
compTemp = 0
Next
End Sub
``````
interestCalculator.jpg
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
ty sooo much
0
Commented:
You're welcome, thanks for the points.
0
Author Commented:
on a side note do you know how to make the text appear in layers

becoming Simple
5%

0
Commented:
Well, it's get a little funky with all the spaces in the code, but if you change the line below I think you will get closer to what you want. It this project will have some longevity, you might consider the gridview as suggested previously. My sample is just a down and dirty way to get quickly formatted results.

``````Me.TextBox2.Text = "      Simple        Compound" & vbCrLf & "         5%              5%" & vbCrLf & vbCrLf
``````
0
Commented:
I am doing this exact same problem, except they want it done using a list box. How do I go about switching the text box method into a list box method?
0
Commented:
Change two lines:

Private Sub Calculate(ByVal amount As String)
Dim amountInt As Integer = Convert.ToInt32(amount)
Dim simple As Integer = amountInt
Dim compound As Integer = amountInt
Dim compTemp As Integer = 0
For i As Integer = 0 To 8
simple += 50
compTemp = compound * 0.05
compound += compTemp
Me.ListBox1.Items.Add(simple.ToString() & "           " & compound.ToString())
compTemp = 0
Next
End Sub
interestCalculator.jpg
0
Commented:
Hello, That solution worked out great, but then I lost the years before the amounts. How would I get them back? And also, how do I go about making the top part look like the example below?

Amount          Amount
Simple            Compound
Year       Interest           Interest

I really appreciate the help.
0
Commented:
You can design your form to display the results any way you like. For example, with this code:

Private Sub Calculate(ByVal amount As String)
Dim amountInt As Integer = Convert.ToInt32(amount)
Dim simple As Integer = amountInt
Dim compound As Integer = amountInt
Dim compTemp As Integer = 0
For i As Integer = 1 To 9
simple += 50
compTemp = compound * 0.05
compound += compTemp
Me.ListBox1.Items.Add("     " & i & ".       " & simple.ToString("C") & "     " & compound.ToString("C"))
compTemp = 0
Next
End Sub

and the attached Designer.vb formatting, I achieved the screen shot below.
``````<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class CompoundInterest
Inherits System.Windows.Forms.Form

'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.ListBox1 = New System.Windows.Forms.ListBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'ListBox1
'
Me.ListBox1.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.ListBox1.FormattingEnabled = True
Me.ListBox1.Location = New System.Drawing.Point(12, 165)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size(187, 156)
Me.ListBox1.TabIndex = 0
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(12, 22)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(82, 13)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Starting Amount"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(95, 19)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(104, 20)
Me.TextBox1.TabIndex = 2
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(124, 54)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 3
Me.Button1.Text = "Calculate"
Me.Button1.UseVisualStyleBackColor = True
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.BackColor = System.Drawing.SystemColors.ControlLightLight
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(12, 112)
Me.Label2.MinimumSize = New System.Drawing.Size(0, 51)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(43, 51)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Year"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.BottomLeft
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.BackColor = System.Drawing.SystemColors.ControlLightLight
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(52, 112)
Me.Label3.MaximumSize = New System.Drawing.Size(70, 0)
Me.Label3.MinimumSize = New System.Drawing.Size(0, 51)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(63, 51)
Me.Label3.TabIndex = 5
Me.Label3.Text = "Amount Simple Interest"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.BackColor = System.Drawing.SystemColors.ControlLightLight
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.Location = New System.Drawing.Point(114, 112)
Me.Label4.MaximumSize = New System.Drawing.Size(85, 0)
Me.Label4.MinimumSize = New System.Drawing.Size(85, 51)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(85, 51)
Me.Label4.TabIndex = 6
Me.Label4.Text = "Amount Compound Interest"
'
'CompoundInterest
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(211, 337)
Me.Name = "CompoundInterest"
Me.Text = "CompoundInterest"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
End Class
``````
interestCalculator.jpg
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.