The following pseudocode should help get you going in the right direction:
if balance is less than 25 then
show label with text "You can't set a payment plan"
else if payment is less then 25 then
show label with text "Minimum payment is 25"
else if paymentamount > balance / 12 then
redirect to page 2
Also, doing things like pmt = Balance.Text / TF
is dangerous - if Balance.Text
is not numeric, you will get an exception.
I suggest using Decimal.TryParse on both Balance.Text
and PmtAmount.Text
to convert the text to a decimal (or show an error if the conversion fails).
EDIT
If Decimal.TryParse(Balance.Text, bal) < 25.0 Then
is not the correct way to use Decimal.TryParse
.
Decimal.TryParse
returns a boolean and stores the result of the conversion in the out parameter, so you need to do something like this:
Dim bal As Decimal
If Not Decimal.TryParse(Balance.Text, bal) Then
' Set the error label letting the user know to enter a number
End If
If the conversion was successful, bal
will have the result of the conversion, and you can use it later in your code.
You can modify the pseudo-code above to something like this:
if balance is not a number or payment amount is not a number
show label with text "balance and payment amount must be a decimal value"
else
if balance is less than 25 then
show label with text "You can't set a payment plan"
else if payment is less then 25 then
show label with text "Minimum payment is 25"
else if paymentamount > balance / 12 then
redirect to page 2
In a nutshell, use Decimal.TryParse
on both balance and payment amount - if either one fails, show an error message.
Otherwise (else) do the rest of your validation using the converted values contained in the out variables.
Code
You're on the right track - your final code would look something like this:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim TF As Decimal = 12 'TimeFrame
Dim Min As Decimal = 25 'Minimum payment plan amount
Dim pmt As Decimal
Dim bal As Decimal
If Not Decimal.TryParse(Balance.Text, bal) OrElse _
Not Decimal.TryParse(PmtAmount.Text, pmt) Then
lblError.Visible = True
lblError.Text = "Balance and Payment Amount must be a decimal"
Else
If bal < 25.0 Then
lblError.Visible = True
lblError.Text = "You can't set a pymt plan, please pay in full"
ElseIf pmt < 25.0 Then
lblError.Visible = True
lblError.Text = "min is 25.00"
ElseIf pmt > (bal / 12) Then
Response.Redirect("default2.aspx")
End If
End If
End Sub