Table of Contents
- Arithmetic Operators
- String Concatenation Operators
- Comparison Operators
- Logical Operators
These operators can be set as VB expressions in the properties of activities or used as conditions for judgments. They can also be combined. When combined, they are interpreted from left to right, but you need to consider the precedence of the operators. You can use parentheses ( ) to specify the precedence. When combining operators, it is better to use parentheses ( ) as needed to ensure the intended operations are performed correctly.
1. Arithmetic Operators
These operators are used for performing calculations, including the four basic arithmetic operations. The rules of calculation are the same as in arithmetic, where multiplication and division take precedence over addition and subtraction. To specify the order of calculations, use parentheses ( ) as in arithmetic.
2. String Concatenation Operators
The "+" operator not only adds numbers but also concatenates strings. When you use the "+" operator with String types (strings), the result is a concatenated string. Even when numbers are stored as strings (String type), they will not be added but concatenated as strings. You can also use the "&" operator for string concatenation.
3. Comparison Operators
Also called relational operators. If the relationship represented by the operator holds, it returns true (True); otherwise, it returns false (False). Comparison operators do not have precedence among themselves. When used with logical operators, comparison operators take precedence.
4. Logical Operators
These operators perform operations on logical values (True/False). They are used when combining multiple conditions. When used with comparison operators, the comparison operators take precedence. Among logical operators, the precedence order is "Not → And → Or → Xor". Use parentheses ( ) to specify the precedence if needed. Let's look at each operator one by one.
Not The "logical negation" operator. Written as "Not condition A". It means "not condition A". If condition A is True, the result is False; if condition A is False, the result is True. For example, to determine if a value is "odd", you can check if "the remainder when divided by 2 is not 0". The expression would be "Not value Mod 2 = 0", which returns True if the value is odd.
Example:
- If var is 10, "10 Mod 2 = 0" is True. Since "Not True" is evaluated, the result is False.
- If var is 5, "5 Mod 2 = 0" is False. Since "Not False" is evaluated, the result is True.
And The "logical conjunction" operator. Written as "condition A And condition B". The result is True only if both condition A and condition B are True. For example, to determine if a value is "even and less than 100", check if "the remainder when divided by 2 is 0 and less than 100". The expression would be "(value Mod 2 = 0) And (value < 100)", which returns True if the value is "even and less than 100".
Example:
- If var is 60, "60 Mod 2 = 0" and "60 < 100" are both True. Since "True And True" is evaluated, the result is True.
- If var is 100, "100 Mod 2 = 0" is True and "100 < 100" is False. Since "True And False" is evaluated, the result is False.
- If var is 3, "3 Mod 2 = 0" is False and "3 < 100" is True. Since "False And True" is evaluated, the result is False.
- If var is 101, "101 Mod 2 = 0" and "101 < 100" are both False. Since "False And False" is evaluated, the result is False.
Or The "logical disjunction" operator. Written as "condition A Or condition B". The result is True if either condition A or condition B is True. For example, to determine if a value is "even or greater than 1000", check if "the remainder when divided by 2 is 0 or greater than 1000". The expression would be "(value Mod 2 = 0) Or (value > 1000)", which returns True if the value is "even or greater than 1000".
Example:
- If var is 1020, "1020 Mod 2 = 0" and "1020 > 1000" are both True. Since "True Or True" is evaluated, the result is True.
- If var is 100, "100 Mod 2 = 0" is True and "100 > 1000" is False. Since "True Or False" is evaluated, the result is True.
- If var is 1001, "1001 Mod 2 = 0" is False and "1001 > 1000" is True. Since "False Or True" is evaluated, the result is True.
- If var is 1, "1 Mod 2 = 0" and "1 > 1000" are both False. Since "False Or False" is evaluated, the result is False.
Xor The "exclusive or" operator. Written as "condition A Xor condition B". The result is True if either condition A or condition B is True, but not both. It is not commonly used.
Example:
- If var is 1020, "1020 Mod 2 = 0" and "1020 > 1000" are both True. Since "True Xor True" is evaluated, the result is False.
- If var is 100, "100 Mod 2 = 0" is True and "100 > 1000" is False. Since "True Xor False" is evaluated, the result is True.
- If var is 1001, "1001 Mod 2 = 0" is False and "1001 > 1000" is True. Since "False Xor True" is evaluated, the result is True.
- If var is 1, "1 Mod 2 = 0" and "1
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article