Boolean Operators

The boolean or logical operators are commonly used to combine Boolean values or expressions into more complex Boolean expressions. For example

Dim i As Integer = 3, j As Integer = 5, b As Boolean
b = i < 5 And j >= 6 ' b is False

The comparison expressions i < 5 and j >= 6 are combined by the logical operator And. And has the exact meaning as in English: if both comparison expressions (i < 5 and j >= 6) are true, the result is True. If at least one of the expressions is false, the result of the logical And operation is False. This result will be assigned to the Boolean variable b.

Visual Basic also has an Or logical operator, which is the equivalent of the English meaning of the word “or”. Here is the same example as before: ...

Get Visual Basic® .NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.