And (operator)

Syntax

expression1 And expression2

Description

Performs a logical or binary conjunction on two expressions.

Comments

If both expressions are either Boolean, Boolean variants, or Null variants, then a logical conjunction is performed as follows:

 

If the first
expression is

and the second
expression is

then the
result is

 

True

True

True

 

True

False

False

 

True

Null

Null

 

False

True

False

 

False

False

False

 

False

Null

Null

 

Null

True

Null

 

Null

False

False

 

Null

Null

Null

 

Binary Conjunction

If the two expressions are Integer, then a binary conjunction is performed, returning an Integer result. All other numeric types (including Empty variants) are converted to Long, and a binary conjunction is then performed, returning a Long result.

Binary conjunction forms a new value based on a bit-by-bit comparison of the binary representations of the two expressions according to the following table:

 

1

And

1

=

1

Example:

 

0

And

1

=

0

5  00001001

 

1

And

0

=

0

6  00001010

 

0

And

0

=

0

And  00001000

Example

Sub Main()

  n1 = 1001
   n2 = 1000
  b1 = True
  b2 = False
  'This example performs a numeric bitwise And operation and stores
  'the result in N3.
  n3 = n1 And n2

'This example performs a logical And comparing b1 and b2 and displays
'the result.
  If b1 And b2 Then
    MsgBox "b1 And b2 are True; n3 is: " & n3
  Else
    MsgBox "b1 And b2 are False; n3 is: " & n3
  End If
End Sub

See Also

Operator Precedence (topic); Or (operator); Xor (operator);  Eqv);(operator); (operator).

 

 

 

 

 

 

 

More information

A