hey guys,
i'm working on this assignment in where I have to take a For...Next Loop and turn it into a Do While Loop. I think I've kinda got the coding down but when I try to calculate the rates the program freezes up. I got the code here, any suggestions on what next because the code doesnt show any errors so i must have mixed something up or something.
thanx
For...Next
Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click
'calculates the monthly payments on a loan using
'terms of 3, 4, and 5 years and interest rates of 5% - 10%
Const TermHeading As String = _
" 3 yrs 4yrs 5yrs"
Dim principal As Double
Dim monthlyPayment As Double
Dim isConverted As Boolean
Me.xPaymentsLabel.Text = String.Empty
isConverted = _
Double.TryParse(Me.xPrincipalTextBox.Text, principal)
If isConverted Then
'display the term in the heading
Me.xPaymentsLabel.Text = TermHeading _
& ControlChars.NewLine
'calculate and display payments
For rate As Double = 0.05 To 0.1 Step 0.01
Me.xPaymentsLabel.Text = Me.xPaymentsLabel.Text _
& rate.ToString("P0") & ""
For term As Double = 3.0 To 5.0
monthlyPayment = _
-Financial.Pmt(rate / 12.0, _
term * 12.0, principal)
Me.xPaymentsLabel.Text = Me.xPaymentsLabel.Text _
& monthlyPayment.ToString("N2") & ""
Next term
Me.xPaymentsLabel.Text = Me.xPaymentsLabel.Text _
& ControlChars.NewLine
Next rate
Else 'principal cannot be converted to a number
MessageBox.Show("Please re-enter the principal. ", _
"Payment Calculator", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End If
Me.xPrincipalTextBox.Focus()
Me.xPrincipalTextBox.SelectAll()
End Sub
End Class
The Do...While that I'm trying to make work
Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click
'calculates the monthly payments on a loan using
'terms of 3, 4, and 5 years and interest rates of 5% - 10%
Const TermHeading As String = _
" 3 yrs 4yrs 5yrs"
Dim principal As Double
Dim monthlyPayment As Double
Dim rate As Double
Dim term As Double
Dim isConverted As Boolean
isConverted = _
Double.TryParse(Me.xPrincipalTextBox.Text, principal)
Do
'calculate and display payments
Do While rate <= 0.1
If isConverted Then
'display the term in the heading
Me.xPaymentsLabel.Text = Me.xPaymentsLabel.Text _
& rate.ToString("P0") & " "
Me.xPaymentsLabel.Text = TermHeading _
& ControlChars.NewLine
ElseIf rate >= 3.0 And rate <= 5.0 Then
monthlyPayment = _
-Financial.Pmt(rate / 12.0, _
term * 12.0, principal)
Me.xPaymentsLabel.Text = Me.xPaymentsLabel.Text _
& monthlyPayment.ToString("N2") & " "
Me.xPaymentsLabel.Text = TermHeading _
& ControlChars.NewLine
ElseIf CBool(term) Then
Me.xPaymentsLabel.Text = Me.xPaymentsLabel.Text _
& ControlChars.NewLine
Else 'principal cannot be converted to a number
MessageBox.Show("Please re-enter the principal. ", _
"Payment Calculator", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Exit Do
End If
Loop
Loop Until Me.xPaymentsLabel.Text = String.Empty
Me.xPrincipalTextBox.Focus()
Me.xPrincipalTextBox.SelectAll()
End Sub
End Class
Once again, thanx for any help/suggestions.