Reputation: 2669
I'm writing an if not statement. When I'm debugging it looks like it should work, but it doesn't.
infotypeid = 68
GlobalEnums.eInfoTypeID.myvar = 68
but its still hitting exit sub:
If (Not infotypeid = GlobalEnums.eInfoTypeID.myvar OrElse Not infotypeid = GlobalEnums.eInfoTypeID.myvar2) Then
Exit Sub
End If
Upvotes: 2
Views: 66
Reputation: 460048
I think you want AndAlso
instead of OrElse
since the former is pointless:
If (Not infotypeid = GlobalEnums.eInfoTypeID.myvar AndAlso Not infotypeid = GlobalEnums.eInfoTypeID.myvar2) Then
Now the If
will be entered on those two eInfoTypeID
values. With OrElse
you would check if it's not eInfoTypeID.myvar
and if that's true
(which means it is eInfoTypeID.myvar
) you check if it's something other.
Another option to increase readability is to use a collection to lookup:
Dim wrongInfoTypes = {GlobalEnums.eInfoTypeID.myvar, GlobalEnums.eInfoTypeID.myvar2}
If Not wrongInfoTypes.Contains(infotypeid) Then
Exit Sub
End If
Upvotes: 2
Reputation: 3962
That's the issue your condition should use AndAlso
instead of OrElse
.
If (Not infotypeid = GlobalEnums.eInfoTypeID.myvar AndAlso _
Not infotypeid = GlobalEnums.eInfoTypeID.myvar2) Then
Exit Sub
End If
Upvotes: 1