VBScript Data Types

VBScript 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.

VBScript doesn’t support explicit declaration of Data Types

char city, int x, float y – C Language

Dim city, x, y – VbScript

city =”Hyderabad”
city =100
city =10.234
city =#10/10/2010#

Only Data type of VBScript is Variant, It can hold any type of Data

VBScript considers data types based on usage of data

Using VarType Function end user can check data sub types

Types of Result in Computer Programming

a) Value based Result


3 + 5 = 8

10 * 3 = 30

10 ^ 3 = 1000

b) Logical Results

Msgbox IsNumeric (100) ‘True

Msgbox IsNumeric (“abcd”) ‘False

c) Constant based Result

Msgbox varType(100) ‘2 for Integer
Msgbox varType(“India”) ‘8 for String

Check Data Sub types using VarType Function

Dim val
Msgbox VarType(val) ‘0 for Uninitialized / Empty

val = “hyderabad”
Msgbox VarType(val) ‘8 for String

Msgbox VarType(“London”) ‘8 for String

val = 100
Msgbox VarType(val) ‘2 for Intiger

val = “100”
Msgbox VarType(val) ‘8 for String

val = 10.234
Msgbox VarType(val) ‘5 for Double

val = #10/10/2010#
Msgbox VarType(val) ‘7 for date

Set val = CreateObject(“Scripting.FileSystemObject”)
Msgbox VarType(val) ‘9 for Automation Object

Convert Data from one sub type to another

Assigning values 2 Types

a) Initialization

x = 100

y =”India”

b) Reading
from input devices
from Files
from databases
from Application objects

Dim a, b
a = InputBox (“Enter A Value”)
b = InputBox (“Enter B Value”)

Msgbox Cint (a) + Cint (b)

When Conversion is required?

When we read data then VBScript considers that data as string type data, in order to perform mathematical calculations we need to convert the data.

Note: We can’t convert Alfa bytes to numbers.
Convert data from One sub type to another
Dim val, Tickets
val = InputBox (“Enter a Value”)
Msgbox VarType(val) ‘8 for string

val = Cint(val)
Msgbox VarType(val)

Tickets = Window(“Flight Reservation”).WinEdit(“Tickets:”).GetROProperty(“text”)
Msgbox VarType(Tickets) ‘8 for string

Tickets = Cint(Tickets)
Msgbox VarType(Tickets) ‘2 for Integer


Dim val, Price
val = InputBox (“Enter a Value”)
Msgbox VarType(val) ‘8 for string

val = Cdbl(val)
Msgbox VarType(val)

Price = Window(“Flight Reservation”).WinEdit(“Price:”).GetROProperty(“text”)
Msgbox VarType(Price) ‘8 for String

Msgbox VarType(Cdbl(Price)) ‘5 for double



This site uses Akismet to reduce spam. Learn how your comment data is processed.