I'm Trying to use event textbox change but I have an error "Input string was not in a correct format "
Is there something wrong with my code ?
or
Is there something wrong with my code implementation ?
Please Guide me
Thanks
Public Class Payment
Private salesservices As New SalesService()
Private Sub Payment_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim sales = salesservices.GetSales(LblInvono.Text)
LabelTotalvalue.Text = sales.Totalinv.ToString("N0")
txtDiscount.Text = sales.DiscountTotal.ToString("N0")
txtPayment.Text = (sales.CashPayment + sales.NCashPayment).ToString("N0")
LabelChange.Text = ((sales.CashPayment + sales.NCashPayment + sales.DiscountTotal) - sales.Totalinv).ToString("N0")
End Sub
Private Sub OnTextChanged(sender As Object, e As EventArgs) Handles txtPayment.TextChanged, txtDiscount.TextChanged
Dim payment As Double = 0
Dim discount As Double = 0
If Not String.IsNullOrEmpty(txtPayment.Text) OrElse Not String.IsNullOrEmpty(txtDiscount.Text) Then
'Error code below this line
payment = Convert.ToDouble(txtPayment.Text)
discount = Convert.ToDouble(txtDiscount.Text)
LabelChange.Text = (Convert.ToDouble(LabelTotalvalue.Text) - discount - payment).ToString("N0")
Else
LabelChange.Text = "-" & Convert.ToDouble(LabelTotalvalue.Text).ToString("N0")
End If
End Sub
Private Sub OnText_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPayment.KeyPress, txtDiscount.KeyPress
If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub txtPayment_KeyUp(sender As Object, e As KeyEventArgs) Handles txtPayment.KeyUp
txtPayment.Text = txtPayment.Text.Replace(",", "")
Dim discount As Double = 0
Dim payment As Double = 0
If Not String.IsNullOrEmpty(txtPayment.Text) Then
payment = Convert.ToDouble(txtPayment.Text)
LabelChange.Text = (Convert.ToDouble(LabelTotalvalue.Text) - discount - payment).ToString("N0")
txtPayment.Text = Convert.ToDouble(txtPayment.Text).ToString("N0")
txtPayment.[Select](txtPayment.Text.Length, 0)
End If
End Sub
Private Sub txtDiscount_KeyUp(sender As Object, e As KeyEventArgs) Handles txtDiscount.KeyUp
txtDiscount.Text = txtDiscount.Text.Replace(",", "")
Dim discount As Double = 0
Dim payment As Double = 0
If Not String.IsNullOrEmpty(txtDiscount.Text) Then
discount = Convert.ToDouble(txtDiscount.Text)
LabelChange.Text = (Convert.ToDouble(LabelTotalvalue.Text) - discount - Payment).ToString("N0")
txtDiscount.Text = Convert.ToDouble(txtDiscount.Text).ToString("N0")
txtDiscount.[Select](txtDiscount.Text.Length, 0)
End If
End Sub
End Class
OnTextChanged
is shadowing a method on your form. You should fix that.Your OnTextChanged is shadowing a method on your form
You are right, how do I fix the warning?TextBox_OnTextChanged
? But also keep in mind that theOn*
naming convention is for the raising of events, not the handling. You should probably call itTextBox_TextChanged
.