VB Script Data Types

VBScript has only one data type called a Variant. A Variant is a special kind of data type that can contain different kinds of information, depending on how it is used.
Because Variant is the only data type in VBScript, it is also the data type returned by all functions in VBScript.

4.1 Variant Subtypes

Beyond the simple numeric or string classifications, a Variant can make further distinctions about the specific nature of numeric information. For example, we can have numeric information that represents a date or a time. When used with other date or time data, the result is always expressed as a date or a time. We can also have a rich variety of numeric information ranging in size from Boolean values to huge floating-point numbers. These different categories of information that can be contained in a Variant are called subtypes. Most of the time, we can just put the kind of data we want in a Variant, and the Variant behaves in a way that is most appropriate for the data it contains.
The following table shows subtypes of data that a Variant can contain.

Subtype Description

Empty Variant is uninitialized. Value is 0 for numeric variables or a zero-length string ("") for string variables.
Null Variant intentionally contains no valid data.
Boolean Contains either True or False.
Byte Contains integer in the range 0 to 255.
Integer Contains integer in the range -32,768 to 32,767.
Currency -922,337,203,685,477.5808 to 922,337,203,685,477.5807.
Long Contains integer in the range -2,147,483,648 to 2,147,483,647.
Single Contains a single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values.
Double Contains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.
Date (Time) Contains a number that represents a date between January 1, 100 to December 31, 9999.
String Contains a variable-length string that can be up to approximately 2 billion characters in length.
Object Contains an object.
Error Contains an error number.

We can use conversion functions to convert data from one subtype to another. In addition, the VarType function returns information about how your data is stored within a Variant.


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
1) = (Equal to) Used to compare expressions.
2) <> (Not equal to) Used to compare expressions.
3) < Less than 4) > Grater than
5) <= Less than or equal to 6) >= Greater than or equal to
7) Is Object equivalence


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

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.