VB Script Operators:
VB Script has a Full Range of Operators for performing different types of operations.
Four types of operators available in VB Script.
Arithmetic Operators
Comparison Operators
Concatenation Operators
Logical Operators
When several operations occur in an expression, each part is evaluated and resolved in a predetermined order called operator precedence.
You 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.
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.
Arithmetic Operators:
Exponentation operator
Symbol : ^
Description: Raises a number to the power of an exponent.
Syntax: result = number^exponent
Note: If either number or exponent is a Null expression, result is also Null.
Addition operator
Symbol : +
Description: Sums two numbers.
Syntax: result = number1+number2
Note: Although you can also use the + operator to concatenate two character strings, you should use the & operator for concatenation to eliminate ambiguity and provide self-documenting code.
Substraction operator
Symbol : -
Description: Finds the difference between two numbers or indicates the negative value of a numeric expression.
Syntax: result = number1-number2 : -number
Note: If one or both expressions are Null expressions, result is Null. If an expression is Empty, it is treated as if it were 0.
Multiplication operator
Symbol : *
Description: Multiplies two numbers.
Syntax: result = number1*number2
If one or both expressions are Null expressions, result is Null. If an expression is Empty, it is treated as if it were 0.
Division operator
Symbol : /
Description: Divides two numbers and returns a floating-point result.
Syntax: result = number1/number2
Note: If one or both expressions are Null expressions, result is Null. If an expression is Empty, it is treated as if it were 0.
Integer Division operator
Symbol : \
Description: Divides two numbers and returns an integer result.
Syntax: result = number1\number2
Note: Before division is performed, numeric expressions are rounded to Byte, Integer, or Long subtype expressions.
If any expression is Null, result is also Null. Any expression that is Empty is treated as 0.
Modulus arithmetic operator
Symbol : Mod
Description: Divides two numbers and returns only the remainder.
Syntax: result = number1 Mod number2
Notes: The modulus, or remainder, operator divides number1 by number2 (rounding floating-point numbers to integers) and returns only the remainder as result.
If any expression is Null, result is also Null. Any expression that is Empty is treated as 0.
Concatenation operator
Symbol : &
Description: Forces string concatenation of two expressions.
Syntax: result = expression1 & expression2
Notes: Whenever an expression is not a string, it is converted to a String subtype.
If both expressions are Null, result is also Null.
However, if only one expression is Null, that expression is treated as a zero-length string ("") when concatenated with the other expression.
Any expression that is Empty is also treated as a zero-length string.
Comparison Operators:
Equality and Inequality operators
Symbol : =, <, <=, >, >=, <>
Description: Used to compare expressions.
Syntax: result = expression1 comparisonoperator expression2
Note: When comparing two expressions, you may not be able to easily determine whether the expressions are being compared as numbers or as strings.
In operator
Symbol : In
Description: Compares two object reference variables.
Syntax: result = object1 Is object2
Note: If object1 and object2 both refer to the same object, result is True;
if they do not, result is False.
Logical Operators:
Logical Conjuction (And) operator
Symbol : Not
Description: Performs logical negation on an expression.
Syntax: result = Not expression
If Expression is | The result is |
True | False |
False | True |
Null | Null |
Logical Conjunction (And) operator
Symbol : And
Description: Performs a logical conjunction on two expressions.
Syntax: result = expression1 And expression2
The result is | And expression2 is | If expression1 is |
True | True | True |
False | False | True |
Null | Null | True |
False | True | False |
False | False | False |
False | Null | False |
Null | True | Null |
False | False | Null |
Null | Null | Null |
Logical Disjunction (Or) operator
Symbol : Or
Description: Performs a logical disjunction on two expressions.
Syntax: result = expression1 Or expression2
The result is | And expression2 is | If expression1 is |
True | True | True |
True | False | True |
True | Null | True |
True | True | False |
False | False | False |
Null | Null | False |
True | True | Null |
Null | False | Null |
Null | Null | Null |
Logical Exclusion (Xor) operator
Symbol : Xor
Description: Performs a logical exclusion on two expressions.
Syntax: result = expression1 Xor expression2
The result is | And expression2 is | If expression1 is |
False | True | True |
True | False | True |
True | True | False |
False | False | False |
No comments:
Post a Comment