如果用户输入整数以外的值,程序将不会继续执行,但会给出一个消息框,告知出现错误。
这是我现在所拥有的,但它不起作用:
Sub Validation0()
If IsNumeric(curBat) Then
' Here, it still could be an integer or a floating point number
If CLng(curBat) = curBat Then
Else
MessageBox.Show("Please enter a number greater than 0.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
End If
End If
End Sub发布于 2018-05-21 13:35:57
试着使你的代码多样化
1)标识字符串是否为整型
2)然后判断是否大于0
Sub Validation0()
If IsNumeric(curBat) Then
' Here, it still could be an integer or a floating point number
dim curBat2 as integer = Convert.ToInt32(curBat)
If curBat2 > 0 Then
Else
MessageBox.Show("Please enter a number greater than 0.", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1)
End If
End If
End Sub如果要对整数值进行舍入,则使用
Math.Roundoff(curBat2)https://stackoverflow.com/questions/50441742
复制相似问题