VBScript
VBScript
Session 3
What We learn Last seasson?
What We learn Last seasson?
How to declare arrays.
How to declare arrays.
Working with one dimensional a
Working with one dimensional a
multi-dimensional arrays.
dimensional arrays.
Working with Dynamic arrays.
Working with Dynamic arrays.
Arrays utilities (Array,UBound, LBound)
Arrays utilities (Array,UBound, LBound)
Subjets for Session 3
Subjets for Session 3
Const Statement.
Const Statement.
Operators.
Operators.
Arithmetic.
Arithmetic.
Comparision.
Comparision.
Logical.
Logical.
Constants
Constants
Const Statement
Const Statement
[[Public
Public
|| Private
Private
]] Const
Const
constname
constname =
= expression
expression
A constant is a meaningful name that takes the place of a
A constant is a meaningful name that takes the place of a
number or string and never changes.
number or string and never changes.
VBScript defines a number of intrinsic constants.
VBScript defines a number of intrinsic constants.
You create user-defined constants in VBScript using the
You create user-defined constants in VBScript using the
Const
Constants
Constants
Const Statement
Const Statement
You may want to adopt a naming scheme to differentiate constants
You may want to adopt a naming scheme to differentiate constants
from variables.
from variables.
This will prevent you from trying
This will prevent you from trying to reassign constant values while
to reassign constant values while
your script is running.
your script is running.
For example, you might want to use a
For example, you might want to use a "vb" or "con" prefix on your
"vb" or "con" prefix on your
constant names, or you might name your constants in all capital
constant names, or you might name your constants in all capital
letters:
letters:
conMaxValue, vbMyValue, MY_VALUE
conMaxValue, vbMyValue, MY_VALUE
Differentiating constants from variables eliminates
Differentiating constants from variables eliminates confusion as
confusion as
you develop more complex scripts.
you develop more complex scripts.
Const
Const
MyString = "This is my string."
MyString = "This is my string."
Const
Const
MyAge = 19
MyAge = 19
Const
Dani Vainstein
Dani Vainstein 66
VBScript Operators
VBScript Operators
VBScript has a full range of operators, including
VBScript has a full range of operators, including
arithmetic operators, comparison operators,
arithmetic operators, comparison operators,
concatenation operators, and logical operators.
concatenation operators, and logical operators.
When several operations occur in an expression, each
When several operations occur in an expression, each
part is evaluated and resolved in a predetermined order
part is evaluated and resolved in a predetermined order
called operator precedence.
called operator precedence.
You can use parentheses to override the order of
You can use parentheses to override the order of
precedence and force some parts of an expression to be
precedence and force some parts of an expression to be
evaluated before others.
evaluated before others.
Operations within parentheses are always
Operations within parentheses are always
performed before those outside
VBScript Operators
VBScript Operators
When expressions contain operators from more than
When expressions contain operators from more than
one category, arithmetic operators are evaluated first,
one category, arithmetic operators are evaluated first,
comparison operators are evaluated next, and logical
comparison operators are evaluated next, and logical
operators are evaluated last.
operators are evaluated last.
Comparison operators all have equal precedence; that
Comparison operators all have equal precedence; that
is, they are evaluated in the l
is, they are evaluated in the left-to-right order in
eft-to-right order in
which they appear.
which they appear.
Arithmetic and logical operators are evaluated in the
Arithmetic and logical operators are evaluated in the
following order of precedence.
VBScript Operators
VBScript Operators
Arithmetic Operators
Arithmetic Operators
Exponentation operator
Exponentation operator
Symbol Symbol : ^: ^ DescriptionDescription: Raises a number to the power of an : Raises a number to the power of an exponent.exponent. Syntax
Syntax: result: result == numbernumber^^exponentexponent Note
Note: If either: If either number number oror exponent exponent is a Null expression,is a Null expression, result result is alsois also NullNull..
Substraction operator
Substraction operator
SymbolSymbol : -: -Description
Description: Finds the : Finds the difference between two numbers or indicates thedifference between two numbers or indicates the negative value of a
negative value of a numeric expression.numeric expression. Syntax
Syntax: result: result == number1-number2 : -numbernumber1-number2 : -number Note
Note: If one : If one or both expressions are Null expressions,or both expressions are Null expressions, result result isis NullNull. If an. If an expression is
VBScript Operators
VBScript Operators
Arithmetic Operators
Arithmetic Operators
Multiplication
Multiplication operator
operator
SymbolSymbol : *: * Description
Description: Multiplies two numbers.: Multiplies two numbers. Syntax
Syntax: result: result == number1*number2number1*number2 If one or both
If one or both expressions are Null expressions,expressions are Null expressions, result result isis NullNull. If an. If an expression is
expression is EmptyEmpty, it is treated as if it , it is treated as if it were 0.were 0.
Division operator
Division operator
SymbolSymbol : /: / Description
Description: Divides two numbers and returns : Divides two numbers and returns a floating-point result.a floating-point result. Syntax
Syntax: result: result == number1/number2number1/number2 Note
Note: If one : If one or both expressions are Null expressions,or both expressions are Null expressions, result result isis NullNull. If an. If an expression is
VBScript Operators
VBScript Operators
Arithmetic Operators
Arithmetic Operators
Integer Division operator
Integer Division operator
Symbol
Symbol
: \
: \
Description
Description
: Divides two numbers and returns an integer result.
: Divides two numbers and returns an integer result.
Syntax
Syntax
: result
: result =
= number1\number2
number1\number2
Note
Note
: Before division is performed, numeric expressions are
: Before division is
performed, numeric expressions are
rounded to
rounded to Byte
Byte
,, Integer
Integer
, or
, or Long
Long
subtype expressions.
subtype expressions.
If any expression is Null,
If any expression is Null, result
result
is also
is also Null
Null
. Any expression that is
. Any expression that is
Empty is treated as 0.
VBScript Operators
VBScript Operators
Arithmetic Operators
Arithmetic Operators
Modulus arithmetic operator
Modulus arithmetic operator
Symbol
Symbol
: Mod
: Mod
Description
Description
: Divides two numbers and returns only the
: Divides two numbers and returns only the
remainder.
remainder.
Syntax
Syntax
: result
: result =
= number1 Mod number2
number1 Mod number2
Notes
Notes
: The modulus, or remainder, operator divides
: The modulus, or remainder, operator divides number1
number1 by
by
number2
number2
(rounding floating-point numbers to integers) and returns
(rounding floating-point numbers to integers) and returns
only the remainder as
only the remainder as result
result
..
If any expression is Null,
If any expression is Null, result
result
is also
is also Null
Null
. Any expression that is
. Any expression that is
Empty
VBScript Operators
VBScript Operators
Arithmetic Operators
Arithmetic Operators
Addition operator
Addition operator
Symbol
Symbol
: +
: +
Description
Description
: Sums two numbers.
: Sums two numbers.
Syntax
Syntax
: result
: result =
= number1+number2
number1+number2
Note
Note
: Although you can also use the
: Although you can also use the +
+ operator to concatenate
operator to concatenate
two character strings, you should use the
two character strings, you should use the &
&
operator for
operator for
concatenation to eliminate ambiguity and
concatenation to eliminate ambiguity and provide self-documenting
provide self-documenting
code.
VBScript Operators
VBScript Operators
Arithmetic Operators
Arithmetic Operators
Concatenation
Concatenation operator
operator
Symbol
Symbol : & : & Description
Description: Forces string concatenation of two expressions.: Forces string concatenation of two expressions. Syntax
Syntax: result: result == expression1 & expression2expression1 & expression2 Notes
Notes: Whenever an: Whenever an expressionexpression is not a string, it is converted to ais not a string, it is converted to a StringString subtype.
subtype.
If both expressions are Null,
If both expressions are Null, result result is alsois also NullNull.. However, if only one
However, if only one expressionexpression isis NullNull, that expression is treated as a zero-, that expression is treated as a zero-length string ("") when concatenated with the other expression.
length string ("") when concatenated with the other expression. Any expression that is Empty is also treated
VBScript Operators
VBScript Operators
Comparision Operators
Comparision Operators
Equality and Inequality operators
Equality and Inequality operators
Symbol
Symbol : =, <, <=, >, >=, <>: =, <, <=, >, >=, <> Description
Description: Used to : Used to compare expressions.compare expressions. Syntax
Syntax: result: result == expression1 comparisonoperator expression1 comparisonoperator expression2expression2 Note
Note: When comparing two expressions, you may not : When comparing two expressions, you may not be able to easilybe able to easily determine whether the expressions are being compared as numbers or determine whether the expressions are being compared as numbers or asas strings. strings.
In
In operator
operator
Symbol Symbol : In: In DescriptionDescription: Compares two object reference variables.: Compares two object reference variables. Syntax
Syntax: result: result == object1object1 IsIs object2object2 Note
Note: If : If object1object1 andand object2object2 both refer to the same object,both refer to the same object, result result isis TrueTrue;; if they do not,
VBScript Operators
VBScript Operators
Logical Operators
Logical Operators
Logical Conjuction (And)
Logical Conjuction (And) operator
operator
Symbol
Symbol
: Not
: Not
Description
Description
: Performs logical negation on an
: Performs logical negation on an expression.
expression.
Syntax
Syntax
: result
: result =
= Not
Not
expression
expression
N Nuullll NNuullll F Faallssee TTrruuee T Trruuee FFaallssee If
VBScript Operators
VBScript Operators
Logical Operators
Logical Operators
Logical Conjuction (And)
Logical Conjuction (And) operator
operator
SymbolSymbol
: And
: And
Description
Description
: Performs a logical
: Performs a logical conjunction on two expressions.
conjunction on two expressions.
Syntax
Syntax
: result
: result =
= expression1
expression1 And
And
expression2
expression2
Null Null Null Null Null Null False False False False Null Null Null Null True True Null Null False False Null Null False False False False False False False False False False True True False False Null Null Null Null True True False False False False True True True True True True True True The
The result result isis
And expression2 is
And expression2 is
If expression1 is
VBScript Operators
VBScript Operators
Logical Operators
Logical Operators
Logical disjuction (Or) operator
Logical disjuction (Or) operator
Symbol
Symbol
: Or
: Or
Description
Description
: Performs a logical disjunction on two expressions.
: Performs a logical disjunction on two expressions.
Syntax
Syntax
: result
: result =
= expression1
expression1 Or
Or
expression2
expression2
Null Null Null Null Null Null Null Null False False Null Null True True True True Null Null Null Null Null Null False False False False False False False False True True True True False False True True Null Null True True True True False False True True True True True True True True The
The result result isis
And expression2 is
And expression2 is
If expression1 is
VBScript Operators
VBScript Operators
Logical Operators
Logical Operators
Logical Exclusion
Logical Exclusion (Xor)
(Xor) operator
operator
Symbol
Symbol
: Xor
: Xor
DescriptionDescription
: Performs a logical exclusion on two expressions.
: Performs a logical exclusion on two expressions.
SyntaxSyntax
: result
: result =
= expression1
expression1 Xor
Xor
expression2
expression2
False False False False False False True True True True False False True True False False True True False False True True True True The
The result result isis And expression2 is And expression2 is If expression1 If expression1 is is