A few words of thanks would be greatly appreciated.

VBScript - The Data Types

The Variant data type

The type of a variable defines how the computer stores the variable in memory, that is to say the sequence of 0 and 1 in the memory cells. VBScript includes a default data type called the "Variant", which may contain different information depending on the context in which it is used. The interpreter will differently (and automatically) process the variable based on how the later is used (e.g as a number, string of characters. In fact, to define a variable, simply assign a value with the syntax specific to the type that you want to use As follows:
  • a string is enclosed in quotation marks
  • a float number consists of digits and a point
  • an integer consists of numbers only


The Variant subtypes

There are many types of data that correspond to very large numbers, Boolean values ??(true or false), dates, ...
They are refered as being the subtype of the Variant data type. Indeed, it is up to the interpreter to decides the way in which data are typed, but sometimes it can be useful to choose the type of a variable.

Here is a summary of the sub-types

Sub-type Description
EmptyIt is the default value of a variable, that is to say the value of the variable before initialiazation
NullThe the value of a variable when its content is incorrect
BooleanContain the folllwing values True or False
ByteContains an integer between 0 and 255
CurrencyContains a currency value ranging from -922 337 203 685 477.5808 to 922 337 203 685 477.5807
This is a sub-type suitable for large financial values
LongContains a long integer whose value is between -2 147 483 648 to 2 147 483 647
SingleContains a float value ranging between -3,402823E38 and -1,401298E-45 for negative values and between 1,401298E-45 and 3,402823E38 for the positive values
DoubleContains a float value, ranging between 1,79769313486232E308 and -4,94065645841247E-324 for negative values and between 4,94065645841247E-324 to 1,79769313486232E308 for positive values
Date / Timecontains a date between 1th January 100 and 31 December 9999.
StringContains a string that can contain several billion characters
ObjectCan contain any object
ErrorContains an error identifier

Determine the type of data

The VarType function allows you to determine the data type of a (passed as parameter).
The names of the constants are associated with each of these values ??in order to facilitate understanding of the type of data they represent.

Here is the list of these values:

Valeu Constant name Data type
12vbVariantVariant Tables
13vbDataObjectAny Object

Convert the data types

It is sometimes useful to change the type of a variable during the execution of an application. For this reason VBScript provides several functions for data

Function Name Description
AscReturns the ANSI code of the first character of a string
AscBReturns the ANSI code of the first character of a binary string
AscWReturns the Unicode code of the first character of a string
ChrReturns a string of ANSI characters
ChrBReturns a string of ANSI characters (binary)
ChrWReturns a string of Unicode characters
CboolReturns a boolean
CbyteReturns the value converted into Byte
CdateReturns the value converted into Date
CDblReturns the value converted into Double
CintReturns the value converted into Int
CLngReturns the value converted into Long
CSngReturns the value converted into Single
CStrReturns the value converted into String
FixReturns the integer portion of a number
HexReturns the hexadecimal value of a number
IntReturns the integer portion of a number
OctReturns the octal portion of a number
RoundRounds a number to the specified number of decimal
SgnReturns an integer while describing the sign of a number

Original document published on CommentcaMarche.net

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.


This document, titled « VBScript - The Data Types », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).