Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the operator precedence order in Visual Basic 6.0?

Tags:

vb6

What is the operator precedence order in Visual Basic 6.0 (VB6)?

In particular, for the logical operators.

like image 384
Oskar Avatar asked Sep 10 '08 20:09

Oskar


People also ask

What is the correct order of operator precedence?

The logical-AND operator ( && ) has higher precedence than the logical-OR operator ( || ), so q && r is grouped as an operand. Since the logical operators guarantee evaluation of operands from left to right, q && r is evaluated before s-- .

Which operator has the highest precedence in VBA?

Operators are evaluated in the following order: Mathematical, Concatenation, Relational, Logical.

Which has the highest precedence () or?

In Java, parentheses() and Array subscript[] have the highest precedence in Java. For example, Addition and Subtraction have higher precedence than the Left shift and Right shift operators.

What are the operators in Visual Basic?

Visual Basic provides the following types of operators: Arithmetic Operators perform familiar calculations on numeric values, including shifting their bit patterns. Comparison Operators compare two expressions and return a Boolean value representing the result of the comparison.


2 Answers

Arithmetic Operation Precedence Order

  1. ^
  2. - (unary negation)
  3. *, /
  4. \
  5. Mod
  6. +, - (binary addition/subtraction)
  7. &

Comparison Operation Precedence Order

  1. =
  2. <>
  3. <
  4. >
  5. <=
  6. >=
  7. Like, Is

Logical Operation Precedence Order

  1. Not
  2. And
  3. Or
  4. Xor
  5. Eqv
  6. Imp

Source: Sams Teach Yourself Visual Basic 6 in 24 Hours — Appendix A: Operator Precedence

like image 123
Jeremy Avatar answered Oct 03 '22 22:10

Jeremy


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:

If A < B And B < C Then

you are guaranteed the < inequality operators will both be evaluated before the logical And 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.

like image 40
Joel Coehoorn Avatar answered Oct 04 '22 00:10

Joel Coehoorn