Я должен добавить TRY-CATCH, чтобы убедиться, что пользователь вводит числовое значение, а не буквенное значение.Он работает нормально, когда вы вводите письмо и читает «произошла ошибка, пожалуйста, введите цифры», но затем программа останавливается и говорит, что произошла ошибка:
Вот мой код
Dim intPoints As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
txtPoints.Clear()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub btnReward_Click(sender As Object, e As EventArgs) Handles btnReward.Click
Try
intPoints = txtPoints.Text
intPoints = Convert.ToInt32(txtPoints.Text)
Catch ex As Exception
Finally
MessageBox.Show("There was an error, please enter digits")
End Try
'intPoints = Convert.ToInt32(txtPoints.Text)
If txtPoints.Text <= 0 Then
MessageBox.Show("You cannot have less than 0")
End If
If txtPoints.Text = 1 Then
MessageBox.Show("Keep Trying")
End If
If txtPoints.Text = 2 Then
MessageBox.Show("Keep Trying")
End If
If txtPoints.Text = 3 Then
MessageBox.Show("Keep Trying")
End If
If txtPoints.Text = 4 Then
MessageBox.Show("Keep Trying")
End If
If txtPoints.Text = 5 Then
MessageBox.Show("You're Gettomg close, just a few more!")
End If
If txtPoints.Text = 6 Then
MessageBox.Show("You're Gettomg close, just a few more!")
End If
If txtPoints.Text = 7 Then
MessageBox.Show("You're Gettomg close, just a few more!")
End If
If txtPoints.Text = 8 Then
MessageBox.Show("You're Gettomg close, just a few more!")
End If
If txtPoints.Text = 9 Then
MessageBox.Show("Almost, just one more!")
End If
If txtPoints.Text = 10 Then
MessageBox.Show("Awesome! You earned a reward!")
End If
If txtPoints.Text >= 11 Then
MessageBox.Show("You cannot have more than 10 points")
End If
End Sub
' A computer uses
Конечный класс