電卓でゼロ除算の例外をキャッチしようとしていますが、機能していません。どこが間違っているのかわかりませんか?
Private Sub btnEqual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEqual.Click
If lblOperator.Text = "+" Then
txtAnswer.Text = Val(txtNumberOne.Text) + Val(txtNumberTwo.Text)
ElseIf lblOperator.Text = "-" Then
txtAnswer.Text = Val(txtNumberOne.Text) - Val(txtNumberTwo.Text)
ElseIf lblOperator.Text = "x" Then
txtAnswer.Text = Val(txtNumberOne.Text) * Val(txtNumberTwo.Text)
ElseIf lblOperator.Text = "/" Then
Try
txtAnswer.Text = Val(txtNumberOne.Text) / Val(txtNumberTwo.Text)
Catch ex As Exception When Val(txtNumberTwo.Text = 0)
MessageBox.Show("You cannot divdide by zero")
End Try
End If
End Sub