wppiexperts
asked on
If-Then test for multiple values
OK - having a bit of a brain fart here, can't seem to figure this one out
I have a list of codes, some of which I do not want to process and I need to test it via an If-Then block, here is what I have:
If value<>'A' and value <> 'B' and value <> 'C' then
...
Else
...
End if
Now, is this code going to process value and say: "If value <> A, B and C then..." (where value has to equal all 3 and fail all the time) or is it going to process it as "If value <> A or B or C then..." (where value can equal any of the 3 values)?
Or should I write it as:
If value <> 'A' OR value <> 'B' OR value <> 'C' then...
essentiall I want to process on values other than A, B or C.
Thanks!
I have a list of codes, some of which I do not want to process and I need to test it via an If-Then block, here is what I have:
If value<>'A' and value <> 'B' and value <> 'C' then
...
Else
...
End if
Now, is this code going to process value and say: "If value <> A, B and C then..." (where value has to equal all 3 and fail all the time) or is it going to process it as "If value <> A or B or C then..." (where value can equal any of the 3 values)?
Or should I write it as:
If value <> 'A' OR value <> 'B' OR value <> 'C' then...
essentiall I want to process on values other than A, B or C.
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
wppiexperts,
Just FYI, there are multiple solutions to this problem. If you apply De Morgan's law to my first post, you would have an equivalent:
Just FYI, there are multiple solutions to this problem. If you apply De Morgan's law to my first post, you would have an equivalent:
If (value <> A And value <> B And value <> C) Then
...
ASKER
so it looks like if I use the OR condition, I need to group all the tests together. Right now, I don't have parenthesis around any (grouping) of them and that may be why the statement isn't catching the values I'm looking for. I'll give it a shot...thanks!
>essentiall I want to process on values other than A, B or C.
Right. So you were right with your first hunch:
If value<>'A' and value <> 'B' and value <> 'C' then
This means If expression1 is true and expression2 is true and expression3 is true then process, which is what you want. You don't need any parenthesis here, because the order of operators puts comparison before logical operators.
Right. So you were right with your first hunch:
If value<>'A' and value <> 'B' and value <> 'C' then
This means If expression1 is true and expression2 is true and expression3 is true then process, which is what you want. You don't need any parenthesis here, because the order of operators puts comparison before logical operators.
What if value = A? You would have:
(True Or False Or False) = True,
which is not our desired logic.