0

My program works when I input the number but when I backspace it to enter another number it shows an error.

Public Class Form1

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
        Dim calculate = 100
        Label1.Text = "The calculation is " & (TextBox1.Text * calculate)
    End Sub

End Class

form picture

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
sharmajee499
  • 116
  • 5

1 Answers1

0

Before your calculation you have to check that TextBox1.Text <> "".

If TextBox1.Text <> "" Then
    Label1.Text = "The calculation is " & (TextBox1.Text * 100)
Else
    Label1.Text = "no value"
End If
tezzo
  • 10,858
  • 1
  • 25
  • 48
  • @tezzo It would be good if you used [`Option Strict On`](https://stackoverflow.com/a/29985039/1115360) when writing answers as it leads to code which works better and more reliably. – Andrew Morton Mar 01 '19 at 19:02
  • @SandeshSharma Please accept the answer by clicking the check mark (tick mark) to the left of the answer. – Mary Mar 02 '19 at 07:12