Facebook

For any corporate training requirements Please mail To sudhakar@qtpsudhakar.com
New Schedule in MindQ Systems, Madhapur By SUDHAKAR
Course Name Date Time Duration Type Branch
Selenium+Appium 16th October 2017 7.30 AM - 9.00 AM IST 45 Days ClassRoom + Online Mind Q Madhapur
Selenium+Appium 30th October 2017 9.30 AM - 11.00 AM IST 45 Days ClassRoom + Online Mind Q Madhapur

A book "Cracking the QTP interview" authored by Sudhakar.Read More. Buy From FlipKart

Sunday, January 17, 2010

How to find Data Type of a Variable?

The data type of a variable can be indentified in 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

In the 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”
There are some more VBScript Built-in functions to find whether a variable datatype is specific datatype or not.
IsArray – Returns a Boolean value indicating whether a variable is an array or not.
IsDate – Returns a Boolean value indicating whether an expression can be converted to a date.
IsEmpty – Returns a Boolean value indicating whether a variable has been initialized.
IsNull - Returns a Boolean value that indicates whether an expression contains no valid data (Null).
IsNumeric - Returns a Boolean value indicating whether an expression can be evaluated as a number.
IsObject - Returns a Boolean value indicating whether an expression references a valid Automation object.
Built in functions are available for only these datatypes. You can write built function for every datatype like below…

'*******************************
Function IsString(oValue)

If vartype(oValue)=8 then

IsString=true
Else
IsString=False
End If
End Function
'*******************************

3 comments :

  1. Silly ? on VBscript.
    I set value as:
    dim SQLR1
    oCommand.CommandText = "SELECT MAX(BG_VTS) FROM BUG "
    Set SQLR1 = oCommand.Execute
    msgbox (VarType(SQLR1)) '''' 9
    msgbox (IsObject(SQLR1)) '''' True
    msgbox (SQLR1.BG_VTS) ''''**** BIG FAIL

    How do I get the value within SQLR1?
    (10 years ago I would have programmed this in 3 minutes, now I can't seem to remember anything)?

    Thank you for your prompt response,
    AMS...

    ReplyDelete
  2. you Are you trying to get data from DB. If so you should create a db connection. Observe the code in the below link
    http://in.groups.yahoo.com/group/qtpsudhakar/message/505

    ReplyDelete
  3. Thank you for your prompt response. I am attaching to QC to verify last update field (on particular records) to see if I need to run backups (IE: Have the fields been updated today?)
    Since I am attached to the database (being logged onto specific project,) running an sql should return the same.
    Am I being naive in my approach?

    Tna
    AMS...

    ReplyDelete