From Xojo Documentation
result = expression1 And expression2
|result||A Boolean if expression1 and expression2 are booleans; an integer if expression1 and expression2 are integers.|
|expression1||Any valid boolean or integer expression. The data types of expression1 and expression2 must match.|
|expression2||Any valid boolean or integer expression. The data types of expression1 and expression2 must match.|
The And operator is overloaded. You can pass either two booleans or two integers. If you pass two booleans, And performs a logical And operation and returns a boolean. If you pass two integers, it performs a bitwise And operation and returns an integer. In this case, it is equivalent to calling the BitAnd method of the Bitwise class.
The truth table for logical operators is shown below.
If you pass two integers, And returns an integer that is the result of comparing each bit of the two integers and assigning 1 to the bit position in the integer returned if both bits in the same position in the integers passed are 1. Otherwise, 0 is assigned to the bit position.
The following table gives the results for bitwise operators.
The Operator_And function can be used to define the And operator for classes.
Use within If Statements
When used within an If..Then statement, once the first expression results to False, none of the subsequent expressions are evaluated. In this example, the IsValid method is not called because the first expression is False. This is referred to as short-circuit evaluation:
This example uses the And operator to perform logical comparisons.
Dim b As Boolean
Dim c As Boolean // defaults to False
Dim d As Boolean // defaults to False
a = True
b = True
d = a And b // Returns True
d = a And c // Returns False
Using And with Integer values:
To understand how the above evaluates to 4, look at the binary values. The value of 4 is "100" in binary. The value of 5 is "101" binary. If you "And" those two binary values together then only the first "1" is in common. So the result is "100", which is 4.