# Visual Basic Operators

An operator is a symbol that specifies an action to perform in an expression, for example, the ‘+’ symbol in the expression ‘1 + 2’ would add the two numbers together to produce a result. This type of operator is known as an arithmetic operator, however, there are also other groups of operators within Visual Basic that will be explained below.

## Arithmetic Operators

Arithmetic operators allow for mathematical calculations to be carried out.

Operator | Description |
---|---|

+ | Adds two values together. |

– | Subtracts one value from another. |

* | Multiplies two values together. |

/ | Divides one value by another resulting in a floating-point number. |

\ | Divides one value by another resulting in an integer. |

Mod | Calculates the remainder after one value is divided by another. |

^ | The exponentiation operator raises one value to the power of another. |

The following examples show each of these operators in action.

' Variables to use in expressions. Dim a As Integer = 3 Dim b As Integer = 8 Dim c As Double = 0 c = a + b ' c will equal 11. c = b - a ' c will equal 5. c = a * b ' c will equal 24. c = b / a ' c will equal 2.66666666666667. c = b \ a ' c will equal 2. c = b Mod a ' c will equal 2. c = a ^ b ' c will equal 6561.

## Relational Operators

Relational operators compare two values and are used, for example, in ‘If’ statements, which are described in the section on Decision Making. The result of the comparison is either True or False.

Operator | Description |
---|---|

= | Evaluates to True if the two values are equal. |

<> | Evaluates to True if the two values are not equal. |

> | Evaluates to True if the first value is greater than the second. |

< | Evaluates to True if the first value is less than the second. |

>= | Evaluates to True if the first value is greater than or equal to the second. |

<= | Evaluates to True if the first value is less than or equal to the second. |

## Logical Operators

Logical operators are used where it is required to test more than one condition at the same time, for example, in an ‘If’ statement, which is discussed in the section on Decision Making.

Operator | Description |
---|---|

AND | Logical AND operator where operands on both sides must be True to evaluate to True. |

OR | Logical OR operator where only one of the two operands must be True to evaluate to True. |

NOT | Logical NOT operator that can be used in conjunction with ‘AND’ or ‘OR’ to reverse the resulting operand. In the case of ‘AND’, if both conditions evaluate to True, then with the use of the ‘NOT’ operator the result would be False. |

XOR | Logical exclusion OR operator that evaluates to True if one and only one of the operands evaluates to True or if one and only one of the operands evaluates to False. |

## Concatenation Operators

Concatenation operators can be used to concatenate, or join, two values together into a single string.

Operator | Description |
---|---|

& | Concatenates two values together into a single string. |

+ | Concatenates two values together into a single string. |