Visual Basic Operators

In Visual Basic, Operator is a programming element that specifies what kind of an operation need to perform on operands or variables. For example, an addition (+) operator in Visual Basic is used to perform the sum operation on operands.

Visual Basic Operator Types

In Visual Basic different type of operators available, those are

 

Now, we will learn each operator in a detailed manner with examples in Visual Basic programming language.

Visual Basic Arithmetic Operators

In Visual Basic, Arithmetic Operators are useful to perform the basic arithmetic calculations like addition, subtraction, division, etc. based on our requirements.

 

Following table lists the different type of arithmetic operators available in Visual Basic.

 

OperatorDescriptionExample (a = 6, b = 3)
+ It will add two operands. a + b = 9
- It will subtract two operands. a - b = 3
* It will multiply two operands. a * b = 18
/ It divides two numbers and returns a floating-point result. a / b = 2
\ It divides two numbers and returns an integer result. a \ b = 2
Mod It divides two numbers and returns only the remainder. a Mod b = 0
^ It raises a number to the power of another number. a ^ b = 216

Visual Basic Assignment Operators

In Visual Basic, Assignment Operators are useful to assign a new value to the operand.

 

Following table lists the different type of assignment operators available in Visual Basic.

 

OperatorDescriptionExample
= It will assign a value to a variable or property. a = 10
+= It will perform an addition of left and right operands and assign a result to the left operand. a += 10 equals to a = a + 10
-= It will perform a subtraction of left and right operands and assign a result to the left operand. a -= 10 equals to a = a - 10
*= It will perform a multiplication of left and right operands and assign a result to the left operand. a *= 10 equals to a = a * 10
/= It will perform a divison of left and right operands and assign the floading point result to the left operand. a /= 10 equals to a = a / 10
\= It will perform a divison of left and right operands and assign the integer result to the left operand. a \= 10 equals to a = a \ 10
^= It will raises the value of a variable to the power of an expression and assigns the result back to the variable. a ^= 10 equals to a = a ^ 10
&= It will concatenate a String expression to String variable and assigns the result to the variable. a &= "World" equals to a = a & "World"
>>= It will mvoe the left operand bit values to the right based on the number of positions specified by second operand. a >>= 2 equals to a = a >> 2
<<= It will mvoe the left operand bit values to the left based on the number of positions specified by second operand. a <<= 2 equals to a = a << 2

Visual Basic Logical / Bitwise Operators

In Visual Basic, Logical / Bitwise Operators are useful to perform the logical operation between two operands like AND, OR, etc. based on our requirements. The Logical / Bitwise Operators will always work with Boolean expressions (true or false) and return Boolean values.

 

Following table lists the different type of logical / bitwise operators available in Visual Basic.

 

OperatorDescriptionExample (a = True, b = False)
And It will return true if both operands are non zero. a And b = False
Or It will return true if any one operand become a non zero. a Or b = True
Not It will return the reverse of logical state that means if both operands are non zero then it will return false. Not(a And b) = True
Xor It will return true if any one of expression1 and expression2 evaluates to true. a Xor b = True
AndAlso It will perform short-circuiting logical operation and return true if both operands evaluates to true. a AndAlso b = False
OrElse It will perform short-circuiting logical operation and return true if anyone of operand evaluates to true. a OrElse b = True
IsFalse It will determine whether an expression is False.  
IsTrue It will determine whether an expression is True.  

Visual Basic Comparison Operators

In Visual Basic, Comparison Operators are useful to determine whether the defined two operands are equal, greater than or less than, etc. based on our requirements.

 

Following table lists the different type of comparison operators available in Visual Basic.

 

OperatorDescriptionExample (a = 10, b = 5)
< It will return true if right operand greater than left operand. a < b = False
<= It will return true if right operand greater than or equal to left operand. a <= b = False
> It will return true if left operand greater than right operand. a > b = True
>= It will return true if left operand greater than or equal to right operand. a >= b = True
= It will return true if both operands are equal. a = b = False
<> It will return true if both operands are not equal. a <> b = True
Is It will return true if two object references refer to same object.  
IsNot It will return true if two object references refer to different objects.  

Visual Basic Concatenation Operators

In Visual Basic, Concatenation Operators are useful to concatenate defined operands based on our requirements.

 

Following table lists the different type of concatenation operators available in Visual Basic.

 

OperatorDescriptionExample (a = Hello, b = World)
& It will concatenate given two expressions. a & b = HelloWorld
+ It can be used to add two numbers or concatenate two string expressions. a + b = HelloWorld