8 Replies - 3808 Views - Last Post: 01 April 2009 - 11:13 AM Rate Topic: -----

#1 daheels  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-March 09

loan statement project

Posted 31 March 2009 - 08:39 PM

This is a loan statement program. It is used to calculate beginning balance, interest, principal, ending balance, and the periods left in the loan. The program should then loop and display all monthly payments. The scrren shot attached is in debugging mode. I have most of it figured out. The problems I am having are getting the loop to work and getting the periods to display. Thanks in advance for any help.

Option Explicit On
Option Strict On

Public Class Form1
	Dim nme As String
	Dim price As Double
	Dim downpayment As Double
	Dim interestrate As Double
	Dim terms As Double
	Dim bbalance As Double
	Dim interest As Double
	Dim principal As Double
	Dim ebalance As Double
	Dim periods As Double

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		nme = TextBox1.Text
		price = CDbl(TextBox2.Text)
		downpayment = CDbl(TextBox3.Text)
		interestrate = CDbl(TextBox4.Text)
		terms = CDbl(TextBox5.Text)
		bbalance = price - downpayment
		periods = terms * 12

		TextBox2.Text = FormatNumber(TextBox2.Text)
		TextBox3.Text = FormatNumber(TextBox3.Text)
		TextBox4.Text = FormatNumber(TextBox4.Text)

		ListBox1.Items.Add("Payment Schedule")
		ListBox1.Items.Add("------- --------")
		ListBox1.Items.Add("Customer: " & nme)
		ListBox1.Items.Add("Cost: " & FormatNumber(price))
		ListBox1.Items.Add("Down Payment: " & FormatNumber(downpayment))
		ListBox1.Items.Add("Loan Amount: " & FormatNumber(price - downpayment))
		ListBox1.Items.Add("Interest Rate: " & FormatNumber(interestrate))
		ListBox1.Items.Add("Terms: " & terms)
		ListBox1.Items.Add("")

		Dim template As String = "{0, 15} {1, 15} {2, 15} {3, 15} {4, 15}"

		ListBox1.Items.Add(String.Format(template, "Beginning", "", "", "Ending", "Periods"))
		ListBox1.Items.Add(String.Format(template, "Balance", "Interest", "Principal", "Balance", "Remaining"))
		ListBox1.Items.Add(String.Format(template, "---------", "---------", "---------", "---------", "---------"))

		Do Until periods <= 0
			interest = (bbalance * (interestrate / 12))
			principal = -Financial.Pmt(interestrate / 12, terms * 12, bbalance) - interest
			ebalance = bbalance - interest - principal
			periods = periods - 1
		Loop
		ListBox1.Items.Add(String.Format(template, FormatNumber(bbalance), FormatNumber(interest), FormatNumber(principal), FormatNumber(ebalance), periods))

	End Sub
End Class


Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: loan statement project

#2 daheels  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-March 09

Re: loan statement project

Posted 31 March 2009 - 11:36 PM

I have updated the code and am closer, but still can't get the loop to work properly. Here is the updated code and a new debugging screeshot.

Option Explicit On
Option Strict On

Public Class Form1
	Dim nme As String
	Dim price As Double
	Dim downpayment As Double
	Dim interestrate As Double
	Dim terms As Double
	Dim bbalance As Double
	Dim interest As Double
	Dim principal As Double
	Dim ebalance As Double
	Dim periods As Double

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		nme = TextBox1.Text
		price = CDbl(TextBox2.Text)
		downpayment = CDbl(TextBox3.Text)
		interestrate = CDbl(TextBox4.Text)
		terms = CDbl(TextBox5.Text)
		bbalance = price - downpayment
		periods = terms * 12
		interest = (bbalance * (interestrate / 12))


		TextBox2.Text = FormatNumber(TextBox2.Text)
		TextBox3.Text = FormatNumber(TextBox3.Text)
		TextBox4.Text = FormatNumber(TextBox4.Text)

		ListBox1.Items.Add("Payment Schedule")
		ListBox1.Items.Add("------- --------")
		ListBox1.Items.Add("Customer: " & nme)
		ListBox1.Items.Add("Cost: " & FormatNumber(price))
		ListBox1.Items.Add("Down Payment: " & FormatNumber(downpayment))
		ListBox1.Items.Add("Loan Amount: " & FormatNumber(price - downpayment))
		ListBox1.Items.Add("Interest Rate: " & FormatNumber(interestrate))
		ListBox1.Items.Add("Terms: " & terms)
		ListBox1.Items.Add("")

		Dim template As String = "{0, 15} {1, 15} {2, 15} {3, 15} {4, 15}"

		ListBox1.Items.Add(String.Format(template, "Beginning", "", "", "Ending", "Periods"))
		ListBox1.Items.Add(String.Format(template, "Balance", "Interest", "Principal", "Balance", "Remaining"))
		ListBox1.Items.Add(String.Format(template, "---------", "---------", "---------", "---------", "---------"))

		Do Until periods <= 0
			principal = -Financial.Pmt(interestrate / 12, terms * 12, bbalance) - interest
			ebalance = bbalance - principal
			ListBox1.Items.Add(String.Format(template, FormatNumber(bbalance), FormatNumber(interest), FormatNumber(principal), FormatNumber(ebalance), periods))
			bbalance -= principal
			interest = (bbalance * (interestrate / 12))


			periods -= 1


		Loop


	End Sub
End Class



Attached Image
Was This Post Helpful? 0
  • +
  • -

#3 daheels  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-March 09

Re: loan statement project

Posted 01 April 2009 - 08:32 AM

No ideas on this one? I could really use a a little help.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,254
  • Joined: 12-June 08

Re: loan statement project

Posted 01 April 2009 - 08:56 AM

I would wager you might get a reply or two more if you told us what "can't get the loop to work properly" means.

What is the problem you are seeing with the loop?
Was This Post Helpful? 0
  • +
  • -

#5 daheels  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-March 09

Re: loan statement project

Posted 01 April 2009 - 09:11 AM

I need the loop to display the complete payment schedule. The Ending balance should be zero. I have played around with the code a little more and now can get everything in the loop to update properly except for the principal. I have attached my new code and a new debugging screenshot. Thanks again.

Option Explicit On
Option Strict On

Public Class Form1
	Dim nme As String
	Dim price As Double
	Dim downpayment As Double
	Dim interestrate As Double
	Dim terms As Double
	Dim bbalance As Double
	Dim interest As Double
	Dim principal As Double
	Dim ebalance As Double
	Dim periods As Double

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		nme = TextBox1.Text
		price = CDbl(TextBox2.Text)
		downpayment = CDbl(TextBox3.Text)
		interestrate = CDbl(TextBox4.Text)
		terms = CDbl(TextBox5.Text)
		bbalance = price - downpayment
		periods = terms * 12
		interest = (bbalance * (interestrate / 12))
		principal = -Financial.Pmt(interestrate / 12, terms * 12, bbalance) - interest

		TextBox2.Text = FormatNumber(TextBox2.Text)
		TextBox3.Text = FormatNumber(TextBox3.Text)
		TextBox4.Text = FormatNumber(TextBox4.Text)

		ListBox1.Items.Add("Payment Schedule")
		ListBox1.Items.Add("------- --------")
		ListBox1.Items.Add("Customer: " & nme)
		ListBox1.Items.Add("Cost: " & FormatNumber(price))
		ListBox1.Items.Add("Down Payment: " & FormatNumber(downpayment))
		ListBox1.Items.Add("Loan Amount: " & FormatNumber(price - downpayment))
		ListBox1.Items.Add("Interest Rate: " & FormatNumber(interestrate))
		ListBox1.Items.Add("Terms: " & terms)
		ListBox1.Items.Add("")

		Dim template As String = "{0, 15} {1, 15} {2, 15} {3, 15} {4, 15}"

		ListBox1.Items.Add(String.Format(template, "Beginning", "", "", "Ending", "Periods"))
		ListBox1.Items.Add(String.Format(template, "Balance", "Interest", "Principal", "Balance", "Remaining"))
		ListBox1.Items.Add(String.Format(template, "---------", "---------", "---------", "---------", "---------"))

		Do Until periods <= 0

			periods -= 1
			ebalance = bbalance - principal
			ListBox1.Items.Add(String.Format(template, FormatNumber(bbalance), FormatNumber(interest), FormatNumber(principal), FormatNumber(ebalance), periods))
			bbalance -= CDbl(principal)
			interest = CDbl(bbalance * (interestrate / 12))





		Loop


	End Sub
End Class



Attached Image
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,254
  • Joined: 12-June 08

Re: loan statement project

Posted 01 April 2009 - 09:39 AM

Well you don't update your principle variable in your loop.

I don't know.. copy and paste your principle equation inside your do loop.
Was This Post Helpful? 0
  • +
  • -

#7 daheels  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-March 09

Re: loan statement project

Posted 01 April 2009 - 10:39 AM

I have tried multiple different ways of adding the principal equation into the loop and have not had any succes.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,254
  • Joined: 12-June 08

Re: loan statement project

Posted 01 April 2009 - 11:01 AM

View Postdaheels, on 1 Apr, 2009 - 11:39 AM, said:

I have tried multiple different ways of adding the principal equation into the loop and have not had any succes.


I am not sure what that even means. What are you trying to obtain? What have you tried? I would imagine adding the

	   principal = -Financial.Pmt(interestrate / 12, terms * 12, bbalance) - interest 


before your print would be sufficient.
Was This Post Helpful? 0
  • +
  • -

#9 daheels  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-March 09

Re: loan statement project

Posted 01 April 2009 - 11:13 AM

I got it figured out. Thanks for your help modi123_1.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1