Visual Basic 6.0 中的运算符优先顺序是什么?
Visual Basic 6.0 (VB6) 中的运算符优先顺序是什么?
特别是对于逻辑运算符。
What is the operator precedence order in Visual Basic 6.0 (VB6)?
In particular, for the logical operators.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
算术运算优先顺序
^
-
(一元求反)*
、/
\
+
、-
(二进制加/减)&
比较运算优先顺序
=
<>
<
>
<=
>=
Like
、Is
逻辑运算优先顺序
Not
And
Or
Xor< /code>
Eqv
Imp
来源: Sams 在 24 小时内自学 Visual Basic 6 — 附录 A:运算符优先级
Arithmetic Operation Precedence Order
^
-
(unary negation)*
,/
\
Mod
+
,-
(binary addition/subtraction)&
Comparison Operation Precedence Order
=
<>
<
>
<=
>=
Like
,Is
Logical Operation Precedence Order
Not
And
Or
Xor
Eqv
Imp
Source: Sams Teach Yourself Visual Basic 6 in 24 Hours — Appendix A: Operator Precedence
这取决于您是否在调试器中。 真的。嗯,有点像。
当然,括号在前。 然后算术(+、-、*、/等)。 然后进行比较(>、<、= 等)。 然后是逻辑运算符。 诀窍是给定优先级内的执行顺序没有定义。 给定以下表达式:
保证
<
不等运算符都将在逻辑And
比较之前被计算。 但不能保证首先执行哪个不等式比较。IIRC,调试器从左到右执行,但编译后的应用程序从右到左执行。我可以把它们倒过来(已经很长一段时间了),但重要的是它们是不同的。 实际优先级不会改变,但执行顺序可能会改变。
It depends on whether or not you're in the debugger. Really. Well, sort of.
Parentheses come first, of course. Then arithmateic (+,-,*,/, etc). Then comparisons (>, <, =, etc). Then the logical operators. The trick is the order of execution within a given precedence level is not defined. Given the following expression:
you are guaranteed the
<
inequality operators will both be evaluated before the logicalAnd
comparison. But you are not guaranteed which inequality comparison will be executed first.IIRC, the debugger executes left to right, but the compiled application executes right to left. I could have them backwards (it's been a long time), but the important thing is they're different. The actual precedence doesn't change, but the order of execution might.
使用括号
编辑:这是我对新代码的建议! 但奥斯卡正在阅读别人的代码,所以必须以某种方式弄清楚。 我建议 VBA 手册主题 运算符优先级。 VBA 与 VB6 99% 等效,并且表达式求值 100% 等效。 我已将逻辑运算符信息粘贴到此处。
逻辑运算符按以下优先级顺序求值:
本主题还解释了比较运算符和算术运算符的优先级。
我建议您一旦弄清楚优先级,就将其放入括号中,除非有充分的理由不编辑代码。
Use parentheses
EDIT: That's my advice for new code! But Oscar is reading someone else's code, so must figure it out somehow. I suggest the VBA manual topic Operator Precedence. VBA is 99% equivalent to VB6 - and expression evaluation is 100% equivalent. I have pasted the logical operator information here.
Logical operators are evaluated in the following order of precedence:
The topic also explains precedence for comparison and arithmetic operators.
I would suggest once you have figured out the precendence, you put in parentheses unless there is some good reason not to edit the code.