我正在尝试检查字符串是否为数字但是徒劳无功。这是我的代码:
If Val(fnumField.Text.Trim) > 0 Or fnumField.Text.Trim = "0" Or Val(phnField.Text.Trim) > 0 Or phnField.Text.Trim = "0" Or Val(ophnField.Text.Trim) > 0 Or _
ophnField.Text.Trim = "0" Or Val(treeField.Text.Trim) > 0 Or treeField.Text.Trim = "0" Then
messageBox.Show("number")
Else
messageBox.Show("not number")
EndIf
我遇到的问题是,当我运行程序并在“fnumField”之类的文本字段中插入像“abcd”这样的字符串时,它仍然执行“if”中的代码而不是“else”中的代码。我做得不对劲?
答案 0 :(得分:0)
试试这个:
If (Val(fnumField.Text.Trim) > 0 Or fnumField.Text.Trim = "0") And (Val(phnField.Text.Trim) > 0 Or phnField.Text.Trim = "0") And (Val(ophnField.Text.Trim) > 0 Or
ophnField.Text.Trim = "0") And (Val(treeField.Text.Trim) > 0 Or treeField.Text.Trim = "0") Then
messageBox.Show("number")
Else
messageBox.Show("not number")
EndIf