布尔表达式 - 运算顺序 [英] Boolean Expression - Order of Operations

查看:17
本文介绍了布尔表达式 - 运算顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Excel VBA 中有一个测试:

<上一页>如果 (test1) And (test2) And (test3) Then'做一点事万一

在 C、Java 等中,首先运行 test1,然后是 test2,然后是 test3.至关重要的是,如果 test1 为假,则整个测试都是假的,因此剩余的测试不会运行.

在这种情况下使用 VBA 会发生这种情况吗?如果是,测试按什么顺序运行?

解决方案

在 .NET 之前的所有 VB 中都没有短路之类的东西.即使不需要,也会评估所有表达式.如果您想要短期课程,请使用嵌套的 IF.

I have a test in 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.

Does that happen in this case with VBA? If so, in which order are the tests running?

解决方案

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.

这篇关于布尔表达式 - 运算顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆