vba 布尔表达式 - 运算顺序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/345399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Boolean Expression - Order of Operations
提问by GSerg
I have a test in Excel VBA:
我在 Excel VBA 中有一个测试:
If (test1) And (test2) And (test3) Then 'do something End If
In C, Java, etc. test1 would be run first, then test2, then test3. Critically, if test1 is false the whole test is false so the remaining tests do not run.
在 C、Java 等中,将首先运行 test1,然后是 test2,然后是 test3。关键是,如果 test1 为假,则整个测试为假,因此其余测试不会运行。
Does that happen in this case with VBA? If so, in which order are the tests running?
在这种情况下,VBA 会发生这种情况吗?如果是这样,测试的运行顺序是什么?
回答by GSerg
In all VBs prior to .NET there is no such thing as short-circuit. All expressions will be evaluated even if not required. If you want short-curcuit, do nested IFs.
在 .NET 之前的所有 VB 中,没有短路这样的事情。即使不需要,也将评估所有表达式。如果你想要短期,做嵌套的 IF。