|
-
February 10th, 2009, 03:32 PM
#1
validation problem
Code:
Dim LoanAmount As Decimal
Dim MonthlyPayment As Decimal
Dim IntrestRate As Decimal
Dim Counter As Integer
Dim Balance As Decimal
lblMsg.Text = ""
If IsNumeric(txtLoanAmount.Text) Then
If txtLoanAmount.Text > 0 Then
If IsNumeric(txtMonthlyRePayment.Text) Then
If txtMonthlyRePayment.Text > 0 Then
LoanAmount = txtLoanAmount.Text
MonthlyPayment = txtMonthlyRePayment.Text
IntrestRate = cboIntrestRate.Text
Balance = LoanAmount
Counter = 1
Do While Balance >= 0
Balance = LoanAmount - MonthlyPayment + (LoanAmount * IntrestRate)
LoanAmount = Balance
If Balance >= 0 Then
lstPaymentSchedule.Items.Add("Month " & Counter & " Balance is £" & Math.Round(Balance, 2))
Else
lstPaymentSchedule.Items.Add("Month " & Counter & " Balance is £0.00")
End If
Counter += 1
Loop
Else
lblMsg.Text = "Please enter a value bigger then 0"
End If
Else
lblMsg.Text = "Please enter a valid Monthly Repaymment"
End If
Else
lblMsg.Text = "Please enter a value greater than 0"
End If
Else
lblMsg.Text = "Please enter a valid Loanamount"
End If
End Sub
Then interface is like
Loan amount : ______ (user puts in data)
Monthly repay: ______ (user puts in data)
Intrest rate: ______ (user selects 0.001, 0.002. 0.003. 0.004)
Payment sched:
Month 1 balance =
month 2 balance =
etc
Everything works fine
just got a problem with few amounts e.g
If user puts in
Loan amount: 10000
Month repy: 1
intrest rate: 0.001
program crashes and says
Value was either too large or too small for a Decimal. (Pointing at the Monthly repayment.
ow can i get round dis
Thanks in advance!
-
February 10th, 2009, 07:40 PM
#2
Re: validation problem
Code:
LoanAmount = txtLoanAmount.Text
You are using a STRING value instead of what you need.
Code:
LoanAmount = txtLoanAmount.ToInt32
or whatever.
-
February 10th, 2009, 08:14 PM
#3
Re: validation problem
Thanks for the reply, it's still giving me the same error though!
-
February 10th, 2009, 08:23 PM
#4
Re: validation problem
What line is crashing? Did you change ALL your fields to the proper type?
Post new code.
-
February 10th, 2009, 09:50 PM
#5
Re: validation problem
Code:
Dim LoanAmount As Decimal
Dim MonthlyPayment As Decimal
Dim IntrestRate As Decimal
Dim Counter As Integer
Dim Balance As Decimal
lblMsg.Text = ""
If IsNumeric(txtLoanAmount.Text) Then
If txtLoanAmount.Text > 0 Then
If IsNumeric(txtMonthlyRePayment.Text) Then
If txtMonthlyRePayment.Text > 0 Then
LoanAmount = txtLoanAmount.Text.ToInt32
MonthlyPayment = txtMonthlyRePayment.Text.ToInt32
IntrestRate = cboIntrestRate.Text.ToInt32
Balance = LoanAmount
Counter = 1
Do While Balance >= 0
Balance = LoanAmount - MonthlyPayment + (LoanAmount * IntrestRate)
LoanAmount = Balance
If Balance >= 0 Then
lstPaymentSchedule.Items.Add("Month " & Counter & " Balance is £" & Math.Round(Balance, 2))
Else
lstPaymentSchedule.Items.Add("Month " & Counter & " Balance is £0.00")
End If
Counter += 1
Loop
Else
lblMsg.Text = "Please enter a value bigger then 0"
End If
Else
lblMsg.Text = "Please enter a valid Monthly Repaymment"
End If
Else
lblMsg.Text = "Please enter a value greater than 0"
End If
Else
lblMsg.Text = "Please enter a valid Loanamount"
End If
End Sub
-
February 10th, 2009, 11:05 PM
#6
Re: validation problem
This should get the types correct, but I haven't looked at the logic at all.
Code:
Dim LoanAmount As Decimal
Dim MonthlyPayment As Decimal
Dim IntrestRate As Decimal
Dim Balance As Decimal
Dim Counter As Integer = 1
lblMsg.Text = ""
If IsNumeric(txtLoanAmount.Text) Then
If CDec(txtLoanAmount.Text) > 0 Then
If IsNumeric(txtMonthlyRePayment.Text) Then
If CDec(txtMonthlyRePayment.Text) > 0 Then
LoanAmount = CDec(txtLoanAmount.Text)
MonthlyPayment = CDec(txtMonthlyRePayment.Text)
IntrestRate = CDec(cboIntrestRate.Text)
Balance = LoanAmount
Counter = 1
Do While Balance >= 0
Balance = LoanAmount - MonthlyPayment + (LoanAmount * IntrestRate)
LoanAmount = Balance
If Balance >= 0 Then
lstPaymentSchedule.Items.Add("Month " & Counter & " Balance is £" & Math.Round(Balance, 2))
Else
lstPaymentSchedule.Items.Add("Month " & Counter & " Balance is £0.00")
End If
Counter += 1
Loop
Else
lblMsg.Text = "Please enter a value bigger then 0"
End If
Else
lblMsg.Text = "Please enter a valid Monthly Repaymment"
End If
Else
lblMsg.Text = "Please enter a value greater than 0"
End If
Else
lblMsg.Text = "Please enter a valid Loanamount"
End If
-
February 10th, 2009, 11:35 PM
#7
Re: validation problem
Loan amount: 10000
Month repy: 1
intrest rate: 0.001
it appears to me that your interest in this case would be greater than the payment so the number would grow until it crashes the program. Payment should never be less than the interest due at any given time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|