How to find Data Type of a Variable?

The data type of a variable can be indentified using two VBScript built-in functions.
  1. Vartype 
  2. Typename
Vartype returns a numeric value indicating the sub datatype of a variable.
The below table contains return values that indicate respective subtypes.

Return Value


Sub Datatype


Description

0
vbEmpty
Empty (uninitialized)
1
vbNull
Null (no valid data)
2
vbInteger
Integer
3
vbLong
Long integer
4
vbSingle
Single-precision floating-point number
5
vbDouble
Double-precision floating-point number
6
vbCurrency
Currency
7
vbDate
Date
8
vbString
String
9
vbObject
Automation object
10
vbError
Error
11
vbBoolean
Boolean
12
vbVariant
Variant (used only with arrays of Variants)
13
vbDataObject
A data-access object
17
vbByte
Byte
8192
vbArray
Array
Ex:  
        Dim x
        x=10
        msgbox vartype(x) --> 'Returns 2
Above table 2 indicates vbInteger datatype.So x is an integer type.
Typename directly returns the name of the Sub Datatype of a variable.
 Sub  Datatype
Description
 Byte
 Byte value
 Integer
 Integer value
 Long
 Long integer value
 Single
 Single-precision floating-point value
 Double
 Double-precision floating-point value
 Currency
 Currency value
 Decimal
 Decimal value
 Date
 Date or time value
 String
 Character string value
 Boolean
 Boolean value; True or False
 Empty
 Unitialized
 Null
 No valid data
 <object type>
 Actual type name of an object
 Object
 Generic object
 Unknown
 Unknown object type
 Nothing
 Object variable that doesn't yet refer to an object instance
 Error
 Error
Ex:
Dim x
x=10
msgbox typename(x)  --> 'Returns “Integer”



To receive daily posted JOBS & Interview Questions
Just enter your email address below and click 'Submit'
Enter your email address:

Make sure to activate your subscription by clicking on the activation link sent to your email