Wednesday, December 15, 2010

VB Script Operators

Operators are used for performing mathematical, comparison and logical operations.

VBScript has a full range of operators, including arithmetic operators, comparison operators, concatenation operators, and logical operators.

4.1 Operator Precedence


When several operations occur in an expression, each part is evaluated and resolved in a predetermined order called operator precedence.

We can use parentheses to override the order of precedence and force some parts of an expression to be evaluated before others.

Operations within parentheses are always performed before those outside. Within parentheses, however, standard operator precedence is maintained.

When expressions contain operators from more than one category, arithmetic operators are evaluated first, comparison operators are evaluated next, and logical operators are evaluated last.

Comparison operators all have equal precedence; that is, they are evaluated in the left-to-right order in which they appear.

Arithmetic and logical operators are evaluated in the following order of precedence.

4.2 Arithmetic Operators:

Operator

Description

1) Exponentiation Operator (^)

Raises a number to the power of an exponent.

2) Multiplication Operator (*)

Multiplies two numbers.

3) Division Operator (/)

Divides two numbers and returns a floating-point result.

4) Integer Division Operator (\)

Divides two numbers and returns an integer result.

5) Mod Operator

Divides two numbers and returns only the remainder.

6) Addition Operator (+)

Sums two numbers.

7) Subtraction Operator (-)

Finds the difference between two numbers or indicates the negative value of a numeric expression.

8) Concatenation Operator (&)

Forces string concatenation of two expressions.

4.3 Comparison Operators

Used to compare expressions.

Operator

Description

Operator

Description

1) =

Equal to

5) <=

Less than or equal to

2) <>

Not equal to

6) >=

Greater than or equal to

3) <

Less than

7) Is

Object equivalence

4) >

Grater than





4.4 Concatenation Operators


Operator
Description

1) Addition Operator (+)

Sums two numbers.

If
Then

1) Both expressions are numeric

Add.

2) Both expressions are strings

Concatenate.

3) One expression is numeric and the other is a string

Add.

2) Concatenation Operator (&)

Forces string concatenation of two expressions.

4.5 Logical Operators

Operator

Description

Syntax

1) Not
Performs logical negation on an expression.

result= Not expression

2) And

Performs a logical conjunction on two expressions.

result= expression1 And expression2

3) Or

Performs a logical disjunction on two expressions.

result= expression1 Or expression2

4) Xor

Performs a logical exclusion on two expressions.

result= expression1 Xor expression2

5) Eqv

Performs a logical equivalence on two expressions.

result= expression1 Eqv expression2

6) Imp

Performs a logical implication on two expressions.

result= expression1 Imp expression2