ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Does VBA shortcut "or" statements? (https://www.excelbanter.com/excel-programming/407677-does-vba-shortcut-statements.html)

[email protected]

Does VBA shortcut "or" statements?
 
Thanks.

***

Peter T

Does VBA shortcut "or" statements?
 
Explain the question

Regards,
Peter T

wrote in message
...
Thanks.

***




Rick Rothstein \(MVP - VB\)[_1463_]

Does VBA shortcut "or" statements?
 
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


wrote in message
...
Thanks.

***



Chip Pearson

Does VBA shortcut "or" statements?
 
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)



"Peter T" <peter_t@discussions wrote in message
...
Explain the question

Regards,
Peter T

wrote in message
...
Thanks.

***





Peter T

Does VBA shortcut "or" statements?
 
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

"Chip Pearson" wrote in message
...
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)



"Peter T" <peter_t@discussions wrote in message
...
Explain the question

Regards,
Peter T

wrote in message

...
Thanks.

***








All times are GMT +1. The time now is 06:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com