Operators In Visual Basic

Started by VelMurugan, Jul 24, 2008, 03:35 PM

Previous topic - Next topic

VelMurugan

Operator

Arithmetic Operators

In order to compute inputs from users and to generate results, we need to use various mathematical operators. In Visual Basic, except for + and -, the symbols for the operators are different from normal mathematical operators, as shown in Table 1.

Conditional Operators

To control the VB program flow, we can use various conditional operators. Basically, they resemble mathematical  operators. Conditional operators are very powerful tools, they let the VB program compare data values and then decide what action to take, whether to execute a program or terminate the program and etc. These operators are shown in Table 2.

Logical Operators

In addition to conditional operators, there are a few logical operators which offer added power to the VB programs. There are shown in Table 3.

Table 1: Arithmetic Operators

Operator            Mathematical function                                                                 Example

^                 Exponential                                                                     2^4=16

*                 Multiplication                                                                   4*3=12,   (5*6))2=60

/                  Division                                                                          12/4=3

Mod              Modulus(return the remainder from an integer division)            15 Mod 4=3     255 mod 10=5

\                  Integer Division(discards the decimal places)                         19\4=4

+ or &           String concatenation                                                         "Visual"&"Basic"="Visual Basic"



Table 2: Conditional Operators

Operator                 Meaning

=                         Equal to
>                         More than
<                         Less Than
>=                        More than and equal
<=                        Less than and equal
<>                        Not Equal to
   

Table 3 : Logical Operator

Operator              Meaning

And           Both sides must be true

or           One side or other must be true

Xor          One side or other must be true but not both

Not          Negates truth

* You can also compare strings with the above operators. However, there are certain rules to follows: Upper case letters are less than lowercase letters, "A"<"B"<"C"<"D".......<"Z" and number are less than letters.


[edited name=VelMurugan date=1216894160][/edited]