如何在visual studio中捕获异常后添加变量条件

时间:2016-09-29 18:16:17

标签: vb.net visual-studio-2015

好的,所以我必须捕获介于1-24之间的int数字,任何高于此值的数据(24小时格式)都应该显示标准的messagebox.show错误消息。我试过声明如下:

Dim intNumber As Integer 如果intNumber> 24 show.MessageBox(“仅24小时格式”)`

它不起作用。我不确定以前的情况是否对我的声明有影响。这是我的代码。感谢您的帮助。

'This textbox requests input from user in form of numbers representing Hours of Operation Used and validates data'
Private Sub HoursOfOperation_TextChanged(sender As Object, e As EventArgs) Handles HoursOfOperation.TextChanged
    Try
        Convert.ToDouble(HoursOfOperation.Text)
    Catch ex As Exception
        MessageBox.Show("Please only type numbers!”)
        HoursOfOperation.ClearUndo()

    End Try
End Sub

0 个答案:

没有答案