我试图不寻找值2,但是显示的是“不应该发生”而不是其他“确定”。
If Not InStr("1, 2, 3", "2") Then
MsgBox ("shouldn't happen")
Else
MsgBox ("ok")
End If
我们知道该值在字符串内。但由于某种原因,“不”不起作用。有谁知道为什么吗?
最佳答案
那是因为
?InStr("1, 2, 3", "2")
4
和
?not 4
-5 // bitwise not of 4
这是一个truthy值(cbool(-5) = true
),因此您需要:
if InStr("1, 2, 3", "2") = 0 then
// not found
else
// found
关于string - Excel VBA 指令 if 语句 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17595164/