7 Replies - 884 Views - Last Post: 13 July 2009 - 01:33 PM Rate Topic: -----

#1 Smoked  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-June 09

Need A Little Help Here

Post icon  Posted 06 July 2009 - 03:44 AM

im writing this program for class its supposed to be able to accept loan amount interest rate amount and the term of the loan (in years) and then output how much interest you owe and how much in total you owe

ive been working on this for hours and im noob can anyone give me suggestions for this?

here is my code:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1

	Inherits System.Windows.Forms.Form

	'Declare Variables
	Dim loanAmount As Double
	Dim interestRate As Double
	Dim term As Integer
	Dim isConverted As Boolean
	Dim totalAmount As Integer
	Dim totalInterest As Integer
	Dim monPay As Integer

	'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.lblTitle = New System.Windows.Forms.Label
		Me.lblLoanAmount = New System.Windows.Forms.Label
		Me.lblRate = New System.Windows.Forms.Label
		Me.lblTerm = New System.Windows.Forms.Label
		Me.lblTotalRate = New System.Windows.Forms.Label
		Me.lblTotalAmount = New System.Windows.Forms.Label
		Me.btnCalculate = New System.Windows.Forms.Button
		Me.btnClear = New System.Windows.Forms.Button
		Me.btnExit = New System.Windows.Forms.Button
		Me.txtLoanAmount = New System.Windows.Forms.TextBox
		Me.txtRate = New System.Windows.Forms.TextBox
		Me.txtTerm = New System.Windows.Forms.TextBox
		Me.txtTotalRate = New System.Windows.Forms.TextBox
		Me.txtTotalAmount = New System.Windows.Forms.TextBox
		Me.SuspendLayout()
		'
		'lblTitle
		'
		Me.lblTitle.AutoSize = True
		Me.lblTitle.Location = New System.Drawing.Point(0, 9)
		Me.lblTitle.Name = "lblTitle"
		Me.lblTitle.Size = New System.Drawing.Size(294, 13)
		Me.lblTitle.TabIndex = 0
		Me.lblTitle.Text = "Please Enter The Information Below As Whole Numbers Only"
		'
		'lblLoanAmount
		'
		Me.lblLoanAmount.AutoSize = True
		Me.lblLoanAmount.Location = New System.Drawing.Point(3, 44)
		Me.lblLoanAmount.Name = "lblLoanAmount"
		Me.lblLoanAmount.Size = New System.Drawing.Size(73, 13)
		Me.lblLoanAmount.TabIndex = 1
		Me.lblLoanAmount.Text = "Loan Amount:"
		'
		'lblRate
		'
		Me.lblRate.AutoSize = True
		Me.lblRate.Location = New System.Drawing.Point(3, 72)
		Me.lblRate.Name = "lblRate"
		Me.lblRate.Size = New System.Drawing.Size(71, 13)
		Me.lblRate.TabIndex = 2
		Me.lblRate.Text = "Interest Rate:"
		'
		'lblTerm
		'
		Me.lblTerm.AutoSize = True
		Me.lblTerm.Location = New System.Drawing.Point(3, 99)
		Me.lblTerm.Name = "lblTerm"
		Me.lblTerm.Size = New System.Drawing.Size(103, 13)
		Me.lblTerm.TabIndex = 3
		Me.lblTerm.Text = "Loan Term In Years:"
		'
		'lblTotalRate
		'
		Me.lblTotalRate.AutoSize = True
		Me.lblTotalRate.Location = New System.Drawing.Point(9, 150)
		Me.lblTotalRate.Name = "lblTotalRate"
		Me.lblTotalRate.Size = New System.Drawing.Size(103, 13)
		Me.lblTotalRate.TabIndex = 4
		Me.lblTotalRate.Text = "Total Interest Owed:"
		'
		'lblTotalAmount
		'
		Me.lblTotalAmount.AutoSize = True
		Me.lblTotalAmount.Location = New System.Drawing.Point(9, 185)
		Me.lblTotalAmount.Name = "lblTotalAmount"
		Me.lblTotalAmount.Size = New System.Drawing.Size(104, 13)
		Me.lblTotalAmount.TabIndex = 5
		Me.lblTotalAmount.Text = "Total Amount Owed:"
		'
		'btnCalculate
		'
		Me.btnCalculate.Location = New System.Drawing.Point(13, 238)
		Me.btnCalculate.Name = "btnCalculate"
		Me.btnCalculate.Size = New System.Drawing.Size(75, 23)
		Me.btnCalculate.TabIndex = 6
		Me.btnCalculate.Text = "Calculate"
		Me.btnCalculate.UseVisualStyleBackColor = True
		'
		'btnClear
		'
		Me.btnClear.Location = New System.Drawing.Point(106, 238)
		Me.btnClear.Name = "btnClear"
		Me.btnClear.Size = New System.Drawing.Size(75, 23)
		Me.btnClear.TabIndex = 7
		Me.btnClear.Text = "Clear"
		Me.btnClear.UseVisualStyleBackColor = True
		'
		'btnExit
		'
		Me.btnExit.Location = New System.Drawing.Point(205, 238)
		Me.btnExit.Name = "btnExit"
		Me.btnExit.Size = New System.Drawing.Size(75, 23)
		Me.btnExit.TabIndex = 8
		Me.btnExit.Text = "Exit"
		Me.btnExit.UseVisualStyleBackColor = True
		'
		'txtLoanAmount
		'
		Me.txtLoanAmount.Location = New System.Drawing.Point(113, 37)
		Me.txtLoanAmount.Name = "txtLoanAmount"
		Me.txtLoanAmount.Size = New System.Drawing.Size(146, 20)
		Me.txtLoanAmount.TabIndex = 9
		'
		'txtRate
		'
		Me.txtRate.Location = New System.Drawing.Point(113, 65)
		Me.txtRate.Name = "txtRate"
		Me.txtRate.Size = New System.Drawing.Size(146, 20)
		Me.txtRate.TabIndex = 10
		'
		'txtTerm
		'
		Me.txtTerm.Location = New System.Drawing.Point(113, 91)
		Me.txtTerm.Name = "txtTerm"
		Me.txtTerm.Size = New System.Drawing.Size(146, 20)
		Me.txtTerm.TabIndex = 11
		'
		'txtTotalRate
		'
		Me.txtTotalRate.Location = New System.Drawing.Point(129, 142)
		Me.txtTotalRate.Name = "txtTotalRate"
		Me.txtTotalRate.ReadOnly = True
		Me.txtTotalRate.Size = New System.Drawing.Size(130, 20)
		Me.txtTotalRate.TabIndex = 12
		'
		'txtTotalAmount
		'
		Me.txtTotalAmount.Location = New System.Drawing.Point(129, 177)
		Me.txtTotalAmount.Name = "txtTotalAmount"
		Me.txtTotalAmount.ReadOnly = True
		Me.txtTotalAmount.Size = New System.Drawing.Size(130, 20)
		Me.txtTotalAmount.TabIndex = 13
		'
		'Form1
		'
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(292, 273)
		Me.Controls.Add(Me.txtTotalAmount)
		Me.Controls.Add(Me.txtTotalRate)
		Me.Controls.Add(Me.txtTerm)
		Me.Controls.Add(Me.txtRate)
		Me.Controls.Add(Me.txtLoanAmount)
		Me.Controls.Add(Me.btnExit)
		Me.Controls.Add(Me.btnClear)
		Me.Controls.Add(Me.btnCalculate)
		Me.Controls.Add(Me.lblTotalAmount)
		Me.Controls.Add(Me.lblTotalRate)
		Me.Controls.Add(Me.lblTerm)
		Me.Controls.Add(Me.lblRate)
		Me.Controls.Add(Me.lblLoanAmount)
		Me.Controls.Add(Me.lblTitle)
		Me.Name = "Form1"
		Me.Text = "Quick Loans "
		Me.ResumeLayout(False)
		Me.PerformLayout()

	End Sub
	Friend WithEvents lblTitle As System.Windows.Forms.Label
	Friend WithEvents lblLoanAmount As System.Windows.Forms.Label
	Friend WithEvents lblRate As System.Windows.Forms.Label
	Friend WithEvents lblTerm As System.Windows.Forms.Label
	Friend WithEvents lblTotalRate As System.Windows.Forms.Label
	Friend WithEvents lblTotalAmount As System.Windows.Forms.Label
	Friend WithEvents btnCalculate As System.Windows.Forms.Button
	Friend WithEvents btnClear As System.Windows.Forms.Button
	Friend WithEvents btnExit As System.Windows.Forms.Button
	Friend WithEvents txtLoanAmount As System.Windows.Forms.TextBox
	Friend WithEvents txtRate As System.Windows.Forms.TextBox
	Friend WithEvents txtTerm As System.Windows.Forms.TextBox
	Friend WithEvents txtTotalRate As System.Windows.Forms.TextBox
	Friend WithEvents txtTotalAmount As System.Windows.Forms.TextBox
	' Closes The Form
	Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
		Me.Close()
	End Sub
	' Clears All Text Boxes And Sets Focus To Loan Amount:
	Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
		txtLoanAmount.Clear()
		txtRate.Clear()
		txtTerm.Clear()
		txtTotalAmount.Clear()
		txtTotalRate.Clear()
		txtLoanAmount.Focus()
	End Sub
	'Calculates All Input Numbers And Gives A Return Statement
	Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
		If isConverted = Double.TryParse(txtLoanAmount.Text, loanAmount) Then
			If isConverted = Double.TryParse(txtRate.Text, interestRate) Then
				If isConverted = Integer.TryParse(txtTerm.Text, term) Then
					monPay = Convert.ToDouble(-Financial.Pmt(interestRate / 12, term, loanAmount))
					totalAmount = monPay * 12
					totalInterest = totalAmount - loanAmount
				Else
					txtTotalRate.Text = Convert.ToString(totalInterest)
					txtTotalAmount.Text = Convert.ToString(totalAmount)
				End If
			End If
		End If




	End Sub



i copied the whole code as to i do not know where the rros are

my error keeps saying 'class' statement must end with a matching 'end class' i got a feeling this is sumthing like if/endif but i cannot find it

can anyone help out please?

Is This A Good Question/Topic? 0
  • +

Replies To: Need A Little Help Here

#2 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 401
  • View blog
  • Posts: 2,964
  • Joined: 18-September 06

Re: Need A Little Help Here

Posted 06 July 2009 - 04:11 AM

Go down to the very bottom of your form and type

End class


Was This Post Helpful? 0
  • +
  • -

#3 Smoked  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-June 09

Re: Need A Little Help Here

Posted 06 July 2009 - 04:32 AM

View PostBort, on 6 Jul, 2009 - 03:11 AM, said:

Go down to the very bottom of your form and type

End class



that solved that problem but now the applications isnt calculating like i wanted it to can anyone give any suggestions im completely stumped here


here is the updated code:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1

	Inherits System.Windows.Forms.Form

	'Declare Variables
	Dim loanAmount As Double
	Dim interestRate As Double
	Dim term As Integer
	Dim isConverted As Boolean
	Dim totalAmount As Integer
	Dim totalInterest As Integer
	Dim monPay As Integer

	'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.lblTitle = New System.Windows.Forms.Label
		Me.lblLoanAmount = New System.Windows.Forms.Label
		Me.lblRate = New System.Windows.Forms.Label
		Me.lblTerm = New System.Windows.Forms.Label
		Me.lblTotalRate = New System.Windows.Forms.Label
		Me.lblTotalAmount = New System.Windows.Forms.Label
		Me.btnCalculate = New System.Windows.Forms.Button
		Me.btnClear = New System.Windows.Forms.Button
		Me.btnExit = New System.Windows.Forms.Button
		Me.txtLoanAmount = New System.Windows.Forms.TextBox
		Me.txtRate = New System.Windows.Forms.TextBox
		Me.txtTerm = New System.Windows.Forms.TextBox
		Me.txtTotalRate = New System.Windows.Forms.TextBox
		Me.txtTotalAmount = New System.Windows.Forms.TextBox
		Me.SuspendLayout()
		'
		'lblTitle
		'
		Me.lblTitle.AutoSize = True
		Me.lblTitle.Location = New System.Drawing.Point(0, 9)
		Me.lblTitle.Name = "lblTitle"
		Me.lblTitle.Size = New System.Drawing.Size(294, 13)
		Me.lblTitle.TabIndex = 0
		Me.lblTitle.Text = "Please Enter The Information Below As Whole Numbers Only"
		'
		'lblLoanAmount
		'
		Me.lblLoanAmount.AutoSize = True
		Me.lblLoanAmount.Location = New System.Drawing.Point(3, 44)
		Me.lblLoanAmount.Name = "lblLoanAmount"
		Me.lblLoanAmount.Size = New System.Drawing.Size(73, 13)
		Me.lblLoanAmount.TabIndex = 1
		Me.lblLoanAmount.Text = "Loan Amount:"
		'
		'lblRate
		'
		Me.lblRate.AutoSize = True
		Me.lblRate.Location = New System.Drawing.Point(3, 72)
		Me.lblRate.Name = "lblRate"
		Me.lblRate.Size = New System.Drawing.Size(71, 13)
		Me.lblRate.TabIndex = 2
		Me.lblRate.Text = "Interest Rate:"
		'
		'lblTerm
		'
		Me.lblTerm.AutoSize = True
		Me.lblTerm.Location = New System.Drawing.Point(3, 99)
		Me.lblTerm.Name = "lblTerm"
		Me.lblTerm.Size = New System.Drawing.Size(103, 13)
		Me.lblTerm.TabIndex = 3
		Me.lblTerm.Text = "Loan Term In Years:"
		'
		'lblTotalRate
		'
		Me.lblTotalRate.AutoSize = True
		Me.lblTotalRate.Location = New System.Drawing.Point(9, 150)
		Me.lblTotalRate.Name = "lblTotalRate"
		Me.lblTotalRate.Size = New System.Drawing.Size(103, 13)
		Me.lblTotalRate.TabIndex = 4
		Me.lblTotalRate.Text = "Total Interest Owed:"
		'
		'lblTotalAmount
		'
		Me.lblTotalAmount.AutoSize = True
		Me.lblTotalAmount.Location = New System.Drawing.Point(9, 185)
		Me.lblTotalAmount.Name = "lblTotalAmount"
		Me.lblTotalAmount.Size = New System.Drawing.Size(104, 13)
		Me.lblTotalAmount.TabIndex = 5
		Me.lblTotalAmount.Text = "Total Amount Owed:"
		'
		'btnCalculate
		'
		Me.btnCalculate.Location = New System.Drawing.Point(13, 238)
		Me.btnCalculate.Name = "btnCalculate"
		Me.btnCalculate.Size = New System.Drawing.Size(75, 23)
		Me.btnCalculate.TabIndex = 6
		Me.btnCalculate.Text = "Calculate"
		Me.btnCalculate.UseVisualStyleBackColor = True
		'
		'btnClear
		'
		Me.btnClear.Location = New System.Drawing.Point(106, 238)
		Me.btnClear.Name = "btnClear"
		Me.btnClear.Size = New System.Drawing.Size(75, 23)
		Me.btnClear.TabIndex = 7
		Me.btnClear.Text = "Clear"
		Me.btnClear.UseVisualStyleBackColor = True
		'
		'btnExit
		'
		Me.btnExit.Location = New System.Drawing.Point(205, 238)
		Me.btnExit.Name = "btnExit"
		Me.btnExit.Size = New System.Drawing.Size(75, 23)
		Me.btnExit.TabIndex = 8
		Me.btnExit.Text = "Exit"
		Me.btnExit.UseVisualStyleBackColor = True
		'
		'txtLoanAmount
		'
		Me.txtLoanAmount.Location = New System.Drawing.Point(113, 37)
		Me.txtLoanAmount.Name = "txtLoanAmount"
		Me.txtLoanAmount.Size = New System.Drawing.Size(146, 20)
		Me.txtLoanAmount.TabIndex = 9
		'
		'txtRate
		'
		Me.txtRate.Location = New System.Drawing.Point(113, 65)
		Me.txtRate.Name = "txtRate"
		Me.txtRate.Size = New System.Drawing.Size(146, 20)
		Me.txtRate.TabIndex = 10
		'
		'txtTerm
		'
		Me.txtTerm.Location = New System.Drawing.Point(113, 91)
		Me.txtTerm.Name = "txtTerm"
		Me.txtTerm.Size = New System.Drawing.Size(146, 20)
		Me.txtTerm.TabIndex = 11
		'
		'txtTotalRate
		'
		Me.txtTotalRate.Location = New System.Drawing.Point(129, 142)
		Me.txtTotalRate.Name = "txtTotalRate"
		Me.txtTotalRate.ReadOnly = True
		Me.txtTotalRate.Size = New System.Drawing.Size(130, 20)
		Me.txtTotalRate.TabIndex = 12
		'
		'txtTotalAmount
		'
		Me.txtTotalAmount.Location = New System.Drawing.Point(129, 177)
		Me.txtTotalAmount.Name = "txtTotalAmount"
		Me.txtTotalAmount.ReadOnly = True
		Me.txtTotalAmount.Size = New System.Drawing.Size(130, 20)
		Me.txtTotalAmount.TabIndex = 13
		'
		'Form1
		'
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(292, 273)
		Me.Controls.Add(Me.txtTotalAmount)
		Me.Controls.Add(Me.txtTotalRate)
		Me.Controls.Add(Me.txtTerm)
		Me.Controls.Add(Me.txtRate)
		Me.Controls.Add(Me.txtLoanAmount)
		Me.Controls.Add(Me.btnExit)
		Me.Controls.Add(Me.btnClear)
		Me.Controls.Add(Me.btnCalculate)
		Me.Controls.Add(Me.lblTotalAmount)
		Me.Controls.Add(Me.lblTotalRate)
		Me.Controls.Add(Me.lblTerm)
		Me.Controls.Add(Me.lblRate)
		Me.Controls.Add(Me.lblLoanAmount)
		Me.Controls.Add(Me.lblTitle)
		Me.Name = "Form1"
		Me.Text = "Quick Loans "
		Me.ResumeLayout(False)
		Me.PerformLayout()

	End Sub
	Friend WithEvents lblTitle As System.Windows.Forms.Label
	Friend WithEvents lblLoanAmount As System.Windows.Forms.Label
	Friend WithEvents lblRate As System.Windows.Forms.Label
	Friend WithEvents lblTerm As System.Windows.Forms.Label
	Friend WithEvents lblTotalRate As System.Windows.Forms.Label
	Friend WithEvents lblTotalAmount As System.Windows.Forms.Label
	Friend WithEvents btnCalculate As System.Windows.Forms.Button
	Friend WithEvents btnClear As System.Windows.Forms.Button
	Friend WithEvents btnExit As System.Windows.Forms.Button
	Friend WithEvents txtLoanAmount As System.Windows.Forms.TextBox
	Friend WithEvents txtRate As System.Windows.Forms.TextBox
	Friend WithEvents txtTerm As System.Windows.Forms.TextBox
	Friend WithEvents txtTotalRate As System.Windows.Forms.TextBox
	Friend WithEvents txtTotalAmount As System.Windows.Forms.TextBox
	' Closes The Form
	Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
		Me.Close()
	End Sub
	' Clears All Text Boxes And Sets Focus To Loan Amount:
	Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
		txtLoanAmount.Clear()
		txtRate.Clear()
		txtTerm.Clear()
		txtTotalAmount.Clear()
		txtTotalRate.Clear()
		txtLoanAmount.Focus()
	End Sub
	'Calculates All Input Numbers And Gives A Return Statement
	Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
		If isConverted = Double.TryParse(txtLoanAmount.Text, loanAmount) Then
			If isConverted = Double.TryParse(txtRate.Text, interestRate) Then
				If isConverted = Integer.TryParse(txtTerm.Text, term) Then
					monPay = Convert.ToDouble(-Financial.Pmt(interestRate / 12, term, loanAmount))
					totalAmount = monPay * 12
					totalInterest = totalAmount - loanAmount
				Else
					txtTotalRate.Text = Convert.ToString(totalInterest)
					txtTotalAmount.Text = Convert.ToString(totalAmount)
				End If
			End If
		End If
	End Sub
End Class


Anyone?
Was This Post Helpful? 0
  • +
  • -

#4 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Need A Little Help Here

Posted 06 July 2009 - 08:07 AM

Several problems identified.

1) You are trying to write C code - stop it!
If isConverted = Double.TryParse(txtLoanAmount.Text, loanAmount) Then
In C code it would do an assignment and then check the result - not so in VB. This statement compares the UNINITIALIZED variable isConverted (defaulted to FALSE) to the Boolean result of the TryParse (which succeeds and returns TRUE) hence failing the if as a whole. Just remove the "isConverted = " from all tests.

2) You are performing the wrong calculation with .Pmt - drop the negative sign in front of it and put it in front of the third parameter, the loanAmount.

3) make sure that you enter the interest rate as a decimal - e.g. 7% is 0.07 - that is the format required by the .Pmt calculation

4) Your totalAmount calculation is wrong - it should be monPay * term, assuming term is in months.

5) Remove the Else line - with this you would only display the results as 0.00 only if tryparse failed to convert the term - not what you want todo....

That should get it working.
Was This Post Helpful? 1

#5 Smoked  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-June 09

Re: Need A Little Help Here

Posted 11 July 2009 - 12:43 AM

View Postmark.bottomley, on 6 Jul, 2009 - 07:07 AM, said:

Several problems identified.

1) You are trying to write C code - stop it!
If isConverted = Double.TryParse(txtLoanAmount.Text, loanAmount) Then
In C code it would do an assignment and then check the result - not so in VB. This statement compares the UNINITIALIZED variable isConverted (defaulted to FALSE) to the Boolean result of the TryParse (which succeeds and returns TRUE) hence failing the if as a whole. Just remove the "isConverted = " from all tests.

2) You are performing the wrong calculation with .Pmt - drop the negative sign in front of it and put it in front of the third parameter, the loanAmount.

3) make sure that you enter the interest rate as a decimal - e.g. 7% is 0.07 - that is the format required by the .Pmt calculation

4) Your totalAmount calculation is wrong - it should be monPay * term, assuming term is in months.

5) Remove the Else line - with this you would only display the results as 0.00 only if tryparse failed to convert the term - not what you want todo....

That should get it working.


i guess my instructor must have forgot and showed me c code but that was the example that she gave me for doing this

can anyone try dumbing this down for me?
im having a bit of trouble understanding what your sayign exactly
ive been working on this forever and i still havent figured it out yet
im not asking for a handout just more help

anyone have anymore tips for me to correct this code to calculate the way that i want it to

This post has been edited by Smoked: 11 July 2009 - 12:53 AM

Was This Post Helpful? 0
  • +
  • -

#6 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 176
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Need A Little Help Here

Posted 11 July 2009 - 07:28 AM

Trying for simpler...

1) isConverted = Double.TryParse(txtLoanAmount.Text, loanAmount)

If this is used alone a a single statement, it is an assignment statement that store the Boolean (True or False) result indicating successful conversion into the variable isConverted.

When you wrap it inside an If/Then construct, it acts differently.

If isConverted = Double.TryParse(txtLoanAmount.Text, loanAmount) Then

It now is a comparison - it compares the value stored in isConverted (which defaults to False as it has never been initialized) with the result from the TryParse conversion. The successful conversion gives the result of True, so the If statements are If False = True Then (A failed compare) so they never execute.

The solution to the above problem is to remove the "isConverted =" part of the If contents - all of them and then the If logic will work correctly.

2) Reading the documentation for the .Pmt calculation, you should be negating the loanAmount, not the final result. Corrected line below:

monPay = Convert.ToDouble(Financial.Pmt(interestRate / 12, term, -loanAmount))

3) I hope this one is obvious - the interestRate that is required for the .Pmt calcualtion is a fractional value e.g. 7% should be entered as 0.07, not 7 unless you are going to divide it by 100 when you read/parse it from the textbox.

4) The totalAmount value I assume is for the duration of the loan, not just for one year - if so, then the calculation of:

totalAmount = monPay * 12

should be

totalAmount = monPay * term

to calculate for the full term of the loan - the monthly interest rate is calculated by dividing the annual interest rate, however the totalAmount is calculated over ALL the months of paying off the loan i.e. "term" payments. It is assumed that term is entered as a number of months, not years. If you enter it as years, you will need to multiply it by 12 to get months as you parse that textbox.

5) This one is a logic problem - the else statement line separates the parts that are executed when the If statement returns True from those executed when the If statement returns False. Here the calculation of the output values only occurs if the If statement returns True, however, you only write values to the textboxes when the If statement returns False - values that have not been initialized and default to 0. What I suspect you want to do is calculate the values and then write the result to the textboxes. That is achieved by removing the line "Else" so that both things happen should the TryParse of txtTerm.Text succeed.

If isConverted = Integer.TryParse(txtTerm.Text, term) Then
monPay = Convert.ToDouble(-Financial.Pmt(interestRate / 12, term, loanAmount))
totalAmount = monPay * 12
totalInterest = totalAmount - loanAmount
Else
txtTotalRate.Text = Convert.ToString(totalInterest)
txtTotalAmount.Text = Convert.ToString(totalAmount)
End If

That is about as detailed an explanation as I can manage - I will try to answer any specific follow-on questions you may post.

I believe that the program will work if you make the above mentioned changes - my version did.

Summary:

Remove all occurrences of "isConverted ="
Change .Pmt calculation line as listed
Enter interest and term in the correct units
Correct totalAmount calculation as listed
Remove the Else line as listed
Was This Post Helpful? 1
  • +
  • -

#7 Smoked  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-June 09

Re: Need A Little Help Here

Posted 12 July 2009 - 09:29 PM

ok ive made corrections and its actually getting into the financial pmt function and doing the calculation ( Woot ) but when i calculate both of my answers keep coming out to be 0 can anyone point out an error in my calculations here

got a feeling this is the last time ill be asking for help on this


here is the updated code

	Dim loanAmount As Double
	Dim loanInterest As Double
	Dim loanTerm As Integer
	Dim totalLoanAmount As Integer
	Dim totalInterestAmount As Integer
	Dim isConverted As Boolean
	Dim monPay As Integer

	'Clear Button: Clears All Text Fields And Sets Focus To The Loan Amount Text Box
	Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
		txtLoanAmount.Clear()
		txtLoanTerm.Clear()
		txtLoanInterest.Clear()
		txtTotalAmount.Clear()
		txtTotalInterest.Clear()
		txtLoanAmount.Focus()
	End Sub
	'Exit Button: Exits The Application
	Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
		Me.Close()
	End Sub
	'Calculate Button: Calculates All Input Values Of The Specified Fields And Produces An Output For The User
	Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
		Double.TryParse(txtLoanAmount.Text, loanAmount)
		Double.TryParse(txtLoanInterest.Text, loanInterest)
		If isConverted = Integer.TryParse(txtLoanTerm.Text, loanTerm) Then
			monPay = Convert.ToDouble(Financial.Pmt(loanInterest / 12, loanTerm, -loanAmount))
			totalLoanAmount = monPay * loanTerm
			totalInterestAmount = totalLoanAmount - loanAmount
		Else
			txtTotalInterest.Text = Convert.ToString(totalInterestAmount)
			txtTotalAmount.Text = Convert.ToString(totalLoanAmount)
		End If
	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#8 Smoked  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-June 09

Re: Need A Little Help Here

Posted 13 July 2009 - 01:33 PM

Thanks Mark Really Appreciate your help


finished this and got an A!

problem solved
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1