5

I'm trying to not look for value 2, however "shouldn't happen" gets shown rather then the else, "ok".

If Not InStr("1, 2, 3", "2") Then
    MsgBox ("shouldn't happen")
Else
    MsgBox ("ok")
End If

We know the value is within the string. yet for some reason the "not" is not working. Does anyone know why?

1
  • Read the documentation on MSDN or on your online help. Instr returns the position as an integer, not a boolean. Commented Jul 11, 2013 at 14:25

1 Answer 1

7

Thats because

?InStr("1, 2, 3", "2")
 4 

and

?not 4
-5 // bitwise not of 4

which is a truthy value (cbool(-5) = true), so instead you need to:

if InStr("1, 2, 3", "2") = 0 then
  // not found
else 
  // found
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.