Monday, April 12, 2010

VB Scripting - Data Types

Previous12345678910Next

What are the Data Types in VB Script?


Data types in VB Script is used in context of Variable. There is only one data type in VB Script called as Variant. The specialty of a Variant is that it can hold different forms of data or information within the variable and there is no need to explicitly define the type of data.


A Variant can hold data which contains either a numeric or a string value. The Variant behaves in the way you want i.e. behaves as a numeric value when used in a numeric context and behaves like a string when used in a string context. The only difference is that any data which is enclosed in quotation marks (" ") behaves like a string even though it contains only numbers.

Variant Subtypes


Variant can hold any type of data like Integer, String, Long, Single or double etc. The different categories of information/data which a Variant can hold are called as subtypes.

Below table gives a clear picture of subtypes of data which a Variant can hold or contain.
SubtypeDescription
IntegerThe size is of 2 bytes, Value can be from 0 to 255, The Integer range is from -32,768 to 32,767.
Long Long is for numbering system, The Integer range is from -2,147,483,648 to 2,147,483,647.
SingleHolds small precision, floating point range is from -3.402823E38 to -1.401298E-45 for negative values and for positive values is from 1.401298E-45 to 3.402823E38.
DoubleHolds big precision, floating point range is from -1.79769313486232E308 to -4.94065645841247E-324 for negative values and for positive values is from 4.94065645841247E-324 to 1.79769313486232E308.
CurrencyRanges from -922,337,203,685,477.5808 to 922,337,203,685,477.5807.
Date (Time)The range is between January 1, 100 to December 31, 9999.
ObjectContains an object.
BooleanContains a boolean value either True or False.
EmptyVariant is uninitialized. Value is 0 for numeric variables or a zero-length string ("") for string variables.
NullVariant intentionally contains no valid data.
ByteContains integer in the range 0 to 255.


You can use the conversion functions to convert the data from one subtype to another subtype which will be discussed in Type Cast lesson.

Previous12345678910Next

No comments:

Post a Comment