Operators for Manipulating Data
This article illustrates how to use operators for manipulating data. Data manipulation involves performing calculations on numbers and manipulating strings. Programs manipulate and use variables in many ways, often depending on the type of the data.
Each data type has a number of operations - things that you can do to it. There are 3 major set of operators in most programming languages - Numeric or Arithmetic operators, Comparison operators and Logical operators. Let's know each set in detail.
Numeric or Arithmetic Operators
+ AdditionArithmetic operators for manipulating data include the familiar addition, subtraction, multiplication and division operators. There are some interesting variations such as the modulus (Mod) and integer division (\) available in visual basic. Take a look at the examples below to understand them better.
\ Integer division
Mod Modulus arithmetic
& String concatenation
An Addition operation, the result here is 120
Result=Number1 + Number2
A Subtraction operation, the result here is 10
Result=Number1 - Number2
A Multiplication operation, the result here is 400
Result=Number1 * Number2
A Division operation, the result here is 55.75
Result=Number1 / Number2
An Integer division operation, the result here is 55Note that this operation does not round off the result but eliminates the decimal part all together.
Result=Number1 \ Number2
A Mod operation, the result here is 15. This operation returns the remainder after an integer division operation.
Result=Number1 Mod Number2
A String concatenation operation, the result here is John Sun
Result=Firstname & " " & Lastname
= EqualityThese operators do not modify data. The purpose of a comparison is to produce a Boolean true or false value that can be used somewhere else in your program, usually used in conditional branching and conditional looping blocks. Take a look at the examples below.
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
An Equality check operation, the result here is TRUE
Result=Number1 = Number2
An Inequality check operation, the result here is TRUE
Result=Number1 <> Number2
A Less than operation, the result here is FALSE
Result=Number1 < Number2
A Greater than operation, the result here is TRUE
Result=Number1 > Number2
A Less than or equal to operation, the result here is FALSE
Result=Number1 <= Number2
A Greater than or equal to operation, the result here is TRUE
Result=Number1 >= Number2
Logical OperatorsThe last set of operators for manipulating data are the logical operators. There are two basic logical operators AND and OR, these operators have their own category because they only operate on boolean variables. Let's take a look at some examples.
An AND operation, the result here is TRUE
Result= (Number1 = Number2) AND (Number1 < 200)
An OR operation, the result here is TRUE
Number1=100That covers all the basic operators for manipulating data, the operators mentioned here are some of the commonly used across many languages. There are more operators you will learn about as you start writing programs in visual basic.
Result= (Number1 = Number2) OR (Number1 < 200)
Back to Visual Basic for Beginners