Does VBA shortcut "or" statements?

  • Thread starter Thread starter baobob
  • Start date Start date
No... in expressions containing logical operators (And, Or, Xor, etc.), VB
evaluates every sub-expression even if the first one's evaluation would be
enough to determine the expression's value as a whole.

Rick
 
Explain the question

Shortcutting in this context means that, for example, the right operand of
an OR operation is not evaluated if the left operand is True. Logically,
shortcutting makes sense, because if the left operand is True, there is no
need to evaluate the right operand since the OR is True regardless of the
value of the right operand.

No, VB/VBA does not shortcut operations.


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
I kind of suspected that was what the OP meant but didn't want to second
guess a reply.

Although logically it might seem as though evaluating the right operand is
redundant if the left is true, I assume it always evaluates both as Or works
by doing a Bitwise comparison of the pair.

v = -1 Or -1
v = -1 Or True
v = True Or 0
the above all return -1 but the following returns True.
v = True Or True

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top