Programming with VBScript
VBScript stands for Visual Basic scripting. This scripting language was launched by Microsoft in 1996. Initially this scripting language was developed targeting web developers. Over these years VBScript has advanced itself into many versions evolving itself into a strong language for Automation tools.
1. DATA TYPES:
VBScript has only one data type called a Variant.
VBScript has only one data type called a Variant.
A Variant is a special type of data that can contain different kinds of information, depending upon how it is used. A Variant can contain either numeric or string information, It behaves as a number when you use it in a numeric context, that is, when you do not include the value within double quotes, and as a string when you use it in a string context, that is , when you include the value in double quotes.You can just put the kind of data you want in a Variant, and the Variant behaves in a way that is most appropriate for the data that it contains.
These different categories of information that can be contained in a Variant are called subtypes.
1.1 SUBTYPES:
The following table shows the subtypes of data that a Variant can contain:
You can use conversion functions to convert data from one subtype to another. Ex: CBool, Cbyte,CInt etc.
The VarType and Typename functions can be used to identify the data types of a variable.
Syntax: VarType(variable name)
TypeName(variable name)
TypeName(variable name)
The VarType and TypeName functions can return one of the following values:
If the variable is an Array than VarType() returns 8192 + VarType(array_element).
Example: for an array of integer VarType() will return 8192+2 = 8194.
Comments
Comments are the non executable lines of a script, comments are used in the script for better readability and maintenance. In VBScript comments can be provided in two ways.
Use '(Single Quotes) or REM
Variables
A variable is a convenient placeholder that refers to a computer memory location where you can store program information that may change during the time your script is running. There are two ways you can declare your variables:
Comments are the non executable lines of a script, comments are used in the script for better readability and maintenance. In VBScript comments can be provided in two ways.
Use '(Single Quotes) or REM
Variables
A variable is a convenient placeholder that refers to a computer memory location where you can store program information that may change during the time your script is running. There are two ways you can declare your variables:
1. Explicit declaration: You can declare variables explicitly in your script using:
· DIM : Variables declared with DIM at the script level are available to all procedures within the script. You can declare variables by separating each variable name with a comma.
ex- Dim a , b ,c.At the procedure level, variables are available only within the procedure.
ex- Dim a , b ,c.At the procedure level, variables are available only within the procedure.
· Public : Variables declared using Public statement are available to all the procedures in all scripts of all projects.
· Private: Private variables are available only to the script in which they are declared.
2. Implicit declaration: You can also declare a variable implicitly by simply using its name in your script. In this method directly the name of the variable is used and a value is assigned to a variable whenever required. Formal declaration of variables is not done here.
Constants
The values that do not alter during the entire execution of the program are called as constants. These fixed values are defined in the script using the Const statement. ex- Const myname= " Armani "
Naming Restrictions
Variables names follow the standard rules for naming anything in VBScript. A variable name:
The values that do not alter during the entire execution of the program are called as constants. These fixed values are defined in the script using the Const statement. ex- Const myname= " Armani "
Naming Restrictions
Variables names follow the standard rules for naming anything in VBScript. A variable name:
· Must begin with alphabetic character.
· Cannot contain a period.
· Must not exceed 255 characters.
· Must be unique in the scope in which it is declared.
Operators:
VBScript has a full range of operators, including arithmetic operators, comparison operators, concatenation
operators and 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 parenthesis to override the order of precedence and force some parts of an expression to be evaluated before others. Operations within
parenthesis are always performed before those outside. Within parentheses, however , standard operator precedence is maintained.
When expression 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
VBScript has a full range of operators, including arithmetic operators, comparison operators, concatenation
operators and 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 parenthesis to override the order of precedence and force some parts of an expression to be evaluated before others. Operations within
parenthesis are always performed before those outside. Within parentheses, however , standard operator precedence is maintained.
When expression 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
COMPARISON Operators:
Equality =
Inequality <>
Less than <
Greater than >
Less than or equal to <=
Greater than or equal to >=
Object Equivalence Is
ARITHMETIC Operators:
Exponentiation ^
Unary Negation -
Multiplication *
Division /
Integer Division \
Modulus Mod
Addition +
Subtraction -
Concatenation &
LOGICAL Operators:
Logical Negation Not
Conjunction And
Disjunction Or
Exclusion Xor
Equivalence Eqv
Implication Imp
No comments
Post a Comment