yyyy
VISUAL BASIC OBJECTIVES
OPERATORS • Make proper use of mathematical operators in a
program
• Explain the principle of precedence of the formula
• Familiarize oneself with the use of mathematical
operators together with logical operator
BEFORE DRIVING INTO
THE LESSON, LET US
FIRST UNDERSTAND
THIS CODE.
A SHORT REVIEW: Given: constant value of x,y.
Let x=5 & y=3
(WHAT IS VARIABLE)
Private Sub
Command1_click
Dim x, y as integer
X=val(text1.text)
Y=val(text2.text)
Text3.text= X+Y
End Sub
PROPER USE OF MATHEMATICAL 5 VISUAL BASIC 6
OPERATORS IN A PROGRAM COMPARISON OPERATORS
Operator Description Example (a = 6, b = 3) In Visual Basic, Comparison Operators are
+ It will add two operands. a + b = 9 useful to determine whether the defined
- It will subtract two a - b = 3 two operands are equal, greater than or
operands
less than, etc., based on our requirements.
x It will multiply two a x b = 18
operands.
/ It divides two numbers a / b = 2
and returns a floating-
point result.
mod It divides two numbers a mod b = 0
and returns only the
remainder.
^ It raises a number to the a ^ b = 216
power of another
number.
1
yyyy
THE FOLLOWING TABLE LISTS
THE DIFFERENT COMPARISON
OPERATORS AVAILABLE IN
VISUAL BASIC.
COMPARISON OPERATORS 7 8
Operator Description Example (a = 10, b = 5)
VISUAL BASIC
< It will return true if the right
operand is greater than the
a < b = false CONCATENATION OPERATORS
left operand.
In Visual Basic, Concatenation Operators are useful to concatenate
<= It will return true if the right a < = b = defined operands based on our requirements.
operand is greater than or false
equal to the left operand.
> It will return true if the left a > b = true
operand is greater than the
right operand.
>= It will return true if the left a >= b = true
operand is greater than or
equal to the right operand
= It will return true if both a = b = false
operands are equal.
<> It will return true if both a <> b = true
operands are not equal.
VISUAL BASIC LOGICAL / 9
AND (&&) OR(||) 10
BITWISE OPERATORS T F T F ANSWER
In Visual Basic, Logical / Bitwise Operators are useful ANSWER
1 1 T 1 1 T
to perform the logical operation between two operands
like AND, OR, etc., based on our requirements. The 0 0 F 0 1 T
Logical / Bitwise Operators will always work with
Boolean expressions (true or false) and return Boolean 0 1 F 1 0 T
values.
1 0 F 0 0 F
NOT(!)
!0 ANSWER 1
!1 0
11 12
SAMPLE
x = 3, y=4;
MAKING GENERALIZATION
1.2(x+y)>(x+y)&& (10 > x)
Requirements:
Find the value of the logical operators;
1.And (&&)
2.Or (||)
3.Not(!) = 2(x+y) > (x+y) && !(10>x)
2
yyyy
THANK
YOU