I am trying to execute a scenario which is Deleting the content/value of textbox and then if the textbox is empty it will become 0 automatically.
because every time I execute it it gives me an error like converting string to integer is invalid etc.
I am trying to execute a scenario which is Deleting the content/value of textbox and then if the textbox is empty it will become 0 automatically.
because every time I execute it it gives me an error like converting string to integer is invalid etc.
If I understand you question correctly then this is what you need
https://stackoverflow.com/a/41890237/9651031
Dim count1 As Integer = 0
count1 = ConvertToInteger(a.Text) + ConvertToInteger(b.Text) + ConvertToInteger(c.Text)
txt_display.Text = count1
Private Function ConvertToInteger(ByRef value As String) As Integer
If String.IsNullOrEmpty(value) Then
value = "0"
End If
Return Convert.ToInt32(value)
End Function
play around with it and eventually you will get your desired result
In that case, trigger the TextBox_TextChanged
event:
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
if me.TextBox1.Trim.Lenght = 0 Then
me.TextBox1.Text = "0"
End if
End Sub
Please try this
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) HandlesTextBox1.TextChanged if TextBox1.Text.Trim = "" Then TextBox1.Text = "0" End if End Sub
Put this on the event in which you want it to happen:
If Textbox1.text = nothing then
Textbox1.text = "0"
End if
Based on your question, I understand that you want the textbox to display the number zero whenever it is empty. Correct?
You can check what the current text/value is when text changes or when you leave the textbox.
Then you simply do
if textbox.text="" ' or any form of empty/nothing
textbox.text="0"
end if