我的VB.net应用程序中有这个:
If IsNumeric("0123456789") Then
MsgBox("Yes")
End If
我怎么能把它换成圆形所以只告诉我False
?
答案 0 :(得分:2)
您可以使用Not运算符:
If Not IsNumeric("012345") Then
MessageBox.Show("Not Numeric")
End If
使用IsNumeric
时要小心,因为当你不期待它时它可能会返回true,请看这些例子:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TestNumeric("12345") 'Is
TestNumeric("123e5") 'Is
TestNumeric("1.2345") 'Is
TestNumeric("123EFG") 'Is Not
TestNumeric("EFG1234") 'Is Not
TestNumeric("0x05") 'Is Not
TestNumeric("1,,,234,5") 'Is
TestNumeric("1,.,2.34,5") 'Is Not
End Sub
Private Sub TestNumeric(Number As String)
If Not IsNumeric(Number) Then
MessageBox.Show(Number + " - Not Numeric")
Else
MessageBox.Show(Number + " - Is Numeric")
End If
End Sub
您还需要知道它使用线程的文化来确定有效性,因此在EN-US
中,情况就是这样:
TestNumeric("1,,,234,5") 'Is
TestNumeric("1...234.5") 'Is Not
切换到DE
,即可获得:
TestNumeric("1,,,234,5") 'Is Not
TestNumeric("1...234.5") 'Is