Hello everyone, this is my first time posting on a bulletin board, so forgive me if I am posting in the wrong place.
I am taking a class on Visual Basic and I am using the 2003 version of VB.net.

Here is the scenario: I am trying to write the code to process the users input in a loan payment calculator.

Here is the algorithm I was given to work of off:

The first step in processing the input is to obtain the input. As opposed to coding the click event for a command button, in this case, we are going to take the action when the user clicks on the radio button. But the process is the same for developing the code. Think about what you want to have happen when the user clicks on the radio button. The program should capture the input that the user has entered and process it according to the following algorithm:

Clear out the list box

Display the column headings for Months, Payment and Total Interest in the list box

Get the loan amount
Get the interest amount

Calculate the monthly interest (the payment function needs the interest in terms of months, but the user will be entering an annual interest rate)

If the user clicks on the mortgage radio button, (calculate payments at 15 ad 30 years)
set months = 12 (months) * 15 (years)
calculate monthly payment using the PMT function

Calculate the total interest:
total interest = months * payment - loan amount

display months, payment, and total interest in list box

(repeat for 30 years)

Otherwise, if Car Loan is checked,

loop years from 3 to 7

calculate months, Monthly payment and total interest

display years, monthly payment and total interest

loop

Else (assumes home improvement is checked)

copy code from the car loan above, but loop from 10 To 15 years.

Display the payments and total interest formatted as currency.


this is the code that I have written so far:


' Declares variables
Dim intLoanAmount As Integer = 0 ' loan amount
Dim dblInterest As Double = 0 ' interest rate
Dim dblMonthlyInterest As Double = 0 ' monthly interest rate
Dim decMonthlyPayment As Decimal = 0 ' monthly payment
Dim intMonths As Integer = 0 ' payment period
Dim intYears As Integer = 0 ' repetition counter
Dim dblTotalInterest = 0 ' total interest

' remove text displayed in ListBox
lstOutput.Items.Clear()

' add header to ListBox
lstOutput.Items.Add("Months" & ControlChars.Tab & _
ControlChars.Tab & "Payment" & ControlChars.Tab _
& ControlChars.Tab & "Total Interest")

' retrieve user input and assign values
' to their respective variables
intLoanAmount = Val(txtLoanAmount.Text)
dblInterest = Val(txtAnnualInterest.Text) / 100

' calculating the monthly interest
dblMonthlyInterest = dblInterest / 12

' calculate payment period
intMonths = 12 * 15

' calculate monthly payment using Pmt
decMonthlyPayment = Convert.ToDecimal( _
Pmt(dblMonthlyInterest, intMonths, -intLoanAmount))

' calculate total interest
dblTotalInterest = intMonths * decMonthlyPayment

' display payment value
lstOutput.Items.Add(intMonths & ControlChars.Tab & _
ControlChars.Tab & String.Format("{0:C}", decMonthlyPayment & ControlChars.Tab _
& ControlChars.Tab & dblTotalInterest))




End Sub
End Class



Any help will be greatly appreciated,
Antonio