- Public Class Form6
- Private Sub btnCompute_Click(sender As Object, e As EventArgs) Handles btnCompute.Click
- On Error GoTo MsgDisplay
- txtOutput.Text = txtOne.Text / txtTwo.Text
- Throw New Exception()
- MsgDisplay:
- If (TypeOf Err.GetException() Is System.InvalidCastException) Then
- MsgBox("You can only divide numbers")
- End If
- If (TypeOf Err.GetException() Is System.DivideByZeroException) Then
- MsgBox("You cannot divide number by zero.")
- End If
- End Sub
- Private Sub txtOne_TextChanged(sender As Object, e As EventArgs) Handles txtOne.TextChanged
- End Sub
- Private Sub txtOne_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtOne.KeyPress
- If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
- e.Handled = True
- End If
- End Sub
- Private Sub txtTwo_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtTwo.KeyPress
- If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
- e.Handled = True
- End If
- End Sub
- End Class
- End Sub
[text] affafafawf
Viewer
Editor
You can edit this paste and save as new: