Interpretation order for logical operators

n3olcsatok

New Member
Joined
Jun 7, 2011
Messages
5
Hi there!

I would like make use of the order in which the logical operators, such as AND and OR are interpreted. For example, in C and C++ the AND operator is interpreted from left to right, so if the expression on the left side of the operator is false, the rest is not processed at all.

In particular, with something like the follwing code:

Code:
If myBoolean And foo() Then
where foo() returns a boolean, to do this:
If myBoolean is false, foo() is not executed
If myBoolean is true, foo() is executed and the result is used for the AND expression.


I wonder if anyone knows whether VBA has such an order and what it is like?
 
In VBA all parts of logical operations are evaluated. In VB.NET there are two special operators: AndAlso and OrElse. They are used as you described in your post for C++.
 
Upvote 0
If you make myBoolean global, the first line of foo() could be
Code:
If Not myBoolean Then Exit Function
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top