Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Operators in VB.

NET

www.ustudy.in
Introduction

 Operator is defined as a symbol that operates the variables

and constants to produce a required result.

www.ustudy.in
VB.NET Operators

 Arithmetic operators

 Comparison operators

 Logical operators

 Concatenation operators

www.ustudy.in
Arithmetic operators

 Arithmetic operators are used to perform arithmetic

calculations such as addition and subtraction.

 VB.NET supported arithmetic are listed in the given table.

www.ustudy.in
Example:
Operator Purpose Output
Let a=10
+ Addition b=a+5 55
- Subtraction c=a–5 45
* Multiplication d = a * 10 500
/ Division e=a/6 8.33
Division (integer
\ part only given as f=a\6 8
output)

Modulas
MOD (Remainder after g = a mod 7 1
division)
^ Power h = a^2 2500
= Assignment m = 100
www.ustudy.in
Comparison operators

 Comparison operators are used to compare two or more

values.

 VB.NET supported comparison operators are listed in the

following table.

www.ustudy.in
Example:
Operator Purpose Output
Let a=50
Check if a value is Dim b As Boolean
= FALSE
equal to another b=(a=55)

Check if a value is
<> b=(a<>55) TRUE
not equal to another

Check if a value is
> b=(a>100) FALSE
greater than another

Check if a value is
< b=(a<100) TRUE
less than another
Check if a value is
>= greater than or b=(a>=50) TRUE
equal to another
Check if a value is
<= less than or equal to b=(a<=75) TRUE
another
Check if a string Dim P As string
LIKE matches a given P=“Good” FALSE
pattern b=(“God” LIKE P)
Check if two object
IS references refer to a
www.ustudy.in same object.
Logical operators

 Logical operators are used to perform logical operations such

as AND, OR, NOT on one or more expressions.

www.ustudy.in
AND
 This operator is used as a conjunction of two conditions. The

result of the AND operation is True only if both the conditions

are true.

Syntax:

Result = Expression1 AND Expression2

www.ustudy.in
Result of AND operation table

Expression 1 Expression 2 Result

TRUE TRUE TRUE

TRUE FALSE FALSE

FALSE TRUE FALSE

FALSE FALSE FALSE

www.ustudy.in
Example of AND Operator
Dim a, b, c As Integer

Dim d As Boolean

a = 10

b = 20

c = 30

d = (a<b) AND (b<c) „Returns True‟

d = (a>b) AND (b<c) „Returns False‟


www.ustudy.in
OR
 This operator is used as a disjunction of two conditions. The

result of the OR operator is false only if both the conditions are

false.

Syntax:

Result = Expression1 OR Expression2

www.ustudy.in
Result of OR operation table

Expression 1 Expression 2 Result

TRUE TRUE TRUE

TRUE FALSE TRUE

FALSE TRUE TRUE

FALSE FALSE FALSE

www.ustudy.in
Example of OR Operator
Dim a, b, c As Integer

Dim d As Boolean

a = 10

b = 20

c = 30

d = (a<b) OR (b>c) „Returns True‟

d = (a>b) OR (b>c) „Returns False‟


www.ustudy.in
XOR
 The result this operator is True only if one of the conditions is

true and other is false.

Syntax:

Result = Expression1 XOR Expression2

www.ustudy.in
Result of XOR operation table

Expression 1 Expression 2 Result

TRUE TRUE FALSE

TRUE FALSE TRUE

FALSE TRUE TRUE

FALSE FALSE FALSE

www.ustudy.in
Example of XOR Operator
Dim a, b, c As Integer

Dim d As Boolean

a = 10

b = 20

c = 30

d = (a<b) XOR (b<c) „Returns False‟

d = (a>b) XOR (b<c) „Returns True‟


www.ustudy.in
NOT
 This logical operator is used to perform a logical negation on

a boolean expression.

Syntax:

Result = NOT (boolean Expression)

www.ustudy.in
Result of NOT operation table

Boolean Expression Result

TRUE FALSE

FALSE TRUE

www.ustudy.in
Example of XOR Operator
Dim a, b, c As Integer

Dim d As Boolean

a = 10

b = 20

c = NOT (a>b) „Returns True‟

c = NOT (a<b) „Returns False‟

www.ustudy.in
AndAlso
 This operator is same as AND operator but if the first condition

is false then the second condition is not checked and the

result is false.

Syntax:

Result = Expression 1 AndAlso Expression2

www.ustudy.in
OrElse
 This operator is same as OR operator but if the first condition

is true then the second condition is not checked and the result

is True.

Syntax:

Result = Expression 1 OrElse Expression2

www.ustudy.in
Concatenation operators

 Concatenation operators are used to join two string values.

 & and + are the two concatenation operators available in

VB.NET.

 The operator & is used to concatenate two strings and + is

used to add two numbers and concatenate two strings.

www.ustudy.in
Example of concatenation operators
MsgBox(“Good” & “Night”) „Returns GoodNight‟

MsgBox(“Good” + “Night”) „Returns GoodNight‟

MsgBox(“22” & “33”) „Returns 2233‟

MsgBox(“22” + “33”) „Returns 2233‟

MsgBox(22 + 33) „Returns 55‟

www.ustudy.in
The End

….. Thank You ……

www.ustudy.in

You might also like