aqObject.GetVarType Method

Applies to TestComplete 14.92, last modified on September 16, 2021

Description

Use the GetVarType method to determine the data type of the passed parameter.

Declaration

aqObject.GetVarType(VarParam)

VarParam [in]    Required    Variant    
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

VarParam

The OLEVariant value whose type you want to determine.

Result Value

An integer number that corresponds to one of the following constants:

Note: For the complete list of values, see the Microsoft documentation.

Constant Name Hex Value Integer Value Description
varEmpty 0000h 0 Empty (uninitialized).
varNull 0001h 1 Null (no valid data).
varSmallInt 0002h 2 Signed 16-bit integer.
varInteger 0003h 3 Signed 32-bit integer.
varSingle 0004h 4 Single-precision floating-point number. Number of significant digits: 7-8.
varDouble 0005h 5 Double-precision floating-point number. Number of significant digits: 15-16.
varCurrency 0006h 6 High-precision floating-point number. Number of significant digits: 19-20. Intended to minimize rounding errors in monetary calculations.
varDate 0007h 7 OLE-compatible TDateTime type.
varOleStr 0008h 8 String of 16-bit Unicode characters.
varDispatch 0009h 9 Automation object that implements IDispatch interface. Also, this type is used for native JavaScript, JScript, Python, C#Script and C++Script arrays (see below).
varError 000Ah 10 Code of an OS error.
varBoolean 000Bh 11 Boolean.
varVariant 000Ch 12 Variant.
varUnknown 000Dh 13 Reference to an unknown OLE object.
varShortInt 0010h 16 Signed 8-bit integer.
varByte 0011h 17 Unsigned 8-bit integer.
varWord 0012h 18 Unsigned 16-bit integer.
varLongWord 0013h 19 Unsigned 32-bit integer.
varInt64 0014h 20 Signed 64-bit integer.
varStrArg 48h 72 A COM-compatible string.
varString 100h 256 A reference to a dynamically allocated string (not COM-compatible).
varAny 101h 257 A Variant that can contain any value.
varArray 2000h 8192 Array (but not a native JavaScript, JScript and Python array, see below). Type of array elements is specified by the lower bits. For example, 2003h is an array of integers.
varByRef 4000h 16384 Reference to a value of the type given by the lower bits. For example, 4007h is a reference to a date.

Remarks

For JavaScript, JScript, Python, C#Script and C++Script users: the varArray constant matches the so-called “safe arrays” that are used in VBScript, DelphiScript, Visual Basic 6 and other languages. JavaScript, JScript, Python, C#Script and C++Script use native arrays. For these arrays, GetVarType returns varDispatch, which is also used for objects. To verify that a variable is a native array, you can use the following code:

JavaScript

if (strictEqual(Object.prototype.toString.call(obj), "[object Array]"))
{
  // A native JavaScript array
}
else
{
  // Not a JavaScript array
}

JScript

if (Object.prototype.toString.call(obj) === "[object Array]")
{
  // A native JScript array
}
else
{
  // Not a JScript array
}

Python

if isinstance(obj, list):
  # A native Python array
else:
  # Not a Python array

C++Script, C#Script

if (Object["prototype"]["toString"]["call"](obj) === "[object Array]")
{
  // A native JScript array
}
else
{
  // Not a JScript array
}

Example

The code snippet below demonstrates how to use the GetVarType method. Besides, it introduces a helper GetTypeName routine that returns human-readable descriptions of data type constants.

JavaScript, JScript

function Main()
{
  var TypeID, TypeDescr, Arr;

  TypeID    = GetVarType(255);
  TypeDescr = GetTypeName(TypeID);
  Log.Message("Type: " + TypeID + " - " + TypeDescr);
  // Prints "Type: 3 - Signed 32-bit integer"

  TypeID    = GetVarType(aqDateTime.Now());
  TypeDescr = GetTypeName(TypeID);
  Log.Message("Type: " + TypeID + " - " + TypeDescr);
  // Prints "Type: 7 - Date/Time"        

  Arr       = new Array(1,2,3)
  TypeID    = GetVarType(Arr);
  TypeDescr = GetTypeName(TypeID);
  Log.Message("Type: " + TypeID + " - " + TypeDescr);
  // Prints "Type: 9 - Automation object of IDispatch interface"
}

function GetTypeName(TypeID)
{
  var str = "Unknown";
  switch (TypeID)
  {
     case varEmpty :
       str = "Uninitialized";
       break;
     case varNull :
       str = "Null";
       break;
     case varSmallInt :
       str = "Signed 16-bit integer";
       break;
     case varInteger :
       str = "Signed 32-bit integer";
       break;
     case varSingle :
       str = "Single-precision floating-point number";
       break;
     case varDouble :
       str = "Double-precision floating-point number";
       break;
     case varCurrency :
       str = "Currency. High-precision floating-point number";
       break;
     case varDate :
       str = "Date/Time";
       break;
     case varOleStr :
       str = "String";
       break;
     case varDispatch :
       str = "Automation object of IDispatch interface";
       break;
     case varError :
       str = "Code of an OS error";
       break;
     case varBoolean :
       str = "Boolean";
       break;
     case varVariant :
       str = "Variant";
       break;
     case varShortInt :
       str = "Signed 8-bit integer";
       break;
     case varByte :
       str = "Unsigned 8-bit integer";
       break;
     case varWord :
       str = "Unsigned 16-bit integer";
       break;
     case varLongWord :
       str = "Unsigned 32-bit integer";
       break;
     case varInt64 :
       str = "Signed 64-bit integer";
       break;
  }

  if ((TypeID >= varArray) && (TypeID <= varArray + varInt64))
  {
     str = "Array of " + GetTypeName(TypeID - varArray);
  }
  else if ((TypeID >= varByRef) && (TypeID <= varByRef + varInt64))
  {
     str = "Reference to " + GetTypeName(TypeID - varByRef);
  }

  return str;
}

Python

def Main():
  TypeID = GetVarType(255)
  TypeDescr = GetTypeName(TypeID)
  Log.Message("Type: " + str(TypeID) + " - " + str(TypeDescr))
  # Prints "Type: 3 - Signed 32-bit integer" 
  
  TypeID = GetVarType(aqDateTime.Now())
  TypeDescr = GetTypeName(TypeID)
  Log.Message("Type: " + str(TypeID) + " - " + str(TypeDescr))
  # Prints "Type: 7 - Date/Time"
  
  Arr = [1,2,3]
  TypeID = GetVarType(Arr)
  TypeDescr = GetTypeName(TypeID)
  Log.Message("Type: " + str(TypeID) + " - " + str(TypeDescr));
  # Prints "Type: 9 - Automation object of IDispatch interface"

def GetTypeName(TypeID):
  str = "Unknown"
  if TypeID == varEmpty:
    str = "Uninitialized"
  elif TypeID == varNull:
    str = "Null"
  elif TypeID == varSmallInt:
    str = "Signed 16-bit integer"
  elif TypeID == varInteger:
    str = "Signed 32-bit integer"
  elif TypeID == varSingle:
    str = "Single-precision floating-point number"
  elif TypeID == varDouble:
    str = "Double-precision floating-point number"
  elif TypeID == varCurrency:
    str = "Currency. High-precision floating-point number"
  elif TypeID == varDate:
    str = "Date/Time"
  elif TypeID == varOleStr:
    str = "String"
  elif TypeID == varDispatch:
    str = "Automation object of IDispatch interface"
  elif TypeID == varError:
    str = "Code of an OS error"
  elif TypeID == varBoolean:
    str = "Boolean"
  elif TypeID == varVariant:
    str = "Variant"
  elif TypeID == varShortInt:
    str = "Signed 8-bit integer"
  elif TypeID == varByte:
    str = "Unsigned 8-bit integer"
  elif TypeID == varWord:
    str = "Unsigned 16-bit integer"
  elif TypeID == varLongWord:
    str = "Unsigned 32-bit integer"
  elif TypeID == varInt64:
    str = "Signed 64-bit integer"
  if (TypeID >= varArray) and (TypeID <= varArray + varInt64):
    str = "Array of " + GetTypeName(TypeID - varArray)
  elif (TypeID >= varByRef) and (TypeID <= varByRef + varInt64):
    str = "Reference to " + GetTypeName(TypeID - varByRef)
  return str

VBScript

Sub Main
  Dim TypeID, TypeDescr, Arr

  TypeID    = GetVarType(255)
  TypeDescr = GetTypeName(TypeID)
  Log.Message "Type: " & TypeID & " - " & TypeDescr
  ' Prints "Type: 2 - Signed 16-bit integer"

  TypeID    = GetVarType(aqDateTime.Now)
  TypeDescr = GetTypeName(TypeID)
  Log.Message "Type: " & TypeID & " - " & TypeDescr
  ' Prints "Type: 7 - Date/Time"

  Arr       = Array(10, 20, 30)
  TypeID    = GetVarType(Arr)
  TypeDescr = GetTypeName(TypeID)
  Log.Message "Type: " & TypeID & " - " & TypeDescr
  ' Prints "Type: 8204 - Array of Variant"
End Sub

Function GetTypeName(TypeID)
  GetTypeName = "Unknown"
  Select Case TypeID
     Case varEmpty    : GetTypeName = "Uninitialized"
     Case varNull     : GetTypeName = "Null"
     Case varSmallInt : GetTypeName = "Signed 16-bit integer"
     Case varInteger  : GetTypeName = "Signed 32-bit integer"
     Case varSingle   : GetTypeName = "Single-precision floating-point number"
     Case varDouble   : GetTypeName = "Double-precision floating-point number"
     Case varCurrency : GetTypeName = "Currency. High-precision floating-point number"
     Case varDate     : GetTypeName = "Date/Time"
     Case varOleStr   : GetTypeName = "String"
     Case varDispatch : GetTypeName = "Automation object of IDispatch interface"
     Case varError    : GetTypeName = "Code of an OS error"
     Case varBoolean  : GetTypeName = "Boolean"
     Case varVariant  : GetTypeName = "Variant"
     Case varShortInt : GetTypeName = "Signed 8-bit integer"
     Case varByte     : GetTypeName = "Unsigned 8-bit integer"
     Case varWord     : GetTypeName = "Unsigned 16-bit integer"
     Case varLongWord : GetTypeName = "Unsigned 32-bit integer"
     Case varInt64    : GetTypeName = "Signed 64-bit integer"
  End Select

  If TypeID >= varArray And TypeID <= varArray + varInt64 Then
    GetTypeName = "Array of " & GetTypeName(TypeID - varArray)
  ElseIf TypeID >= varByRef And TypeID <= varByRef + varInt64 Then
    GetTypeName = "Reference to " & GetTypeName(TypeID - varByRef)
  End If
End Function

DelphiScript

function GetTypeName(TypeID); forward;

procedure Main2;
var
  TypeID, TypeDescr;
  Arr : array [0..2];
begin
  TypeID    := GetVarType(255);
  TypeDescr := GetTypeName(TypeID);
  Log.Message('Type: ' + aqConvert.IntToStr(TypeID) + ' - ' + TypeDescr);
  // Prints 'Type: 3 - Signed 32-bit integer'
   
  TypeID    := GetVarType(aqDateTime.Now());
  TypeDescr := GetTypeName(TypeID);
  Log.Message('Type: ' + aqConvert.IntToStr(TypeID) + ' - ' + TypeDescr);
  // Prints 'Type: 7 - Date/Time'
  
  Arr       := [1, 2, 3];
  TypeID    := GetVarType(Arr);
  TypeDescr := GetTypeName(TypeID);
  Log.Message('Type: ' + aqConvert.IntToStr(TypeID) + ' - ' + TypeDescr);
  // Prints 'Type: 8204 - Array of Variant'      
end;

function GetTypeName(TypeID);
begin
  case TypeID of 
     varEmpty    : Result := 'Uninitialized';
     varNull     : Result := 'Null';
     varSmallInt : Result := 'Signed 16-bit integer';
     varInteger  : Result := 'Signed 32-bit integer';
     varSingle   : Result := 'Single-precision floating-point number';
     varDouble   : Result := 'Double-precision floating-point number';
     varCurrency : Result := 'Currency. High-precision floating-point number';
     varDate     : Result := 'Date/Time';
     varOleStr   : Result := 'String';
     varDispatch : Result := 'Automation object of IDispatch interface';
     varError    : Result := 'Code of an OS error';
     varBoolean  : Result := 'Boolean';
     varVariant  : Result := 'Variant';
     varUnknown  : Result := 'Unknown';
     varShortInt : Result := 'Signed 8-bit integer';
     varByte     : Result := 'Unsigned 8-bit integer';
     varWord     : Result := 'Unsigned 16-bit integer';
     varLongWord : Result := 'Unsigned 32-bit integer';
     varInt64    : Result := 'Signed 64-bit integer';
     varArray .. varArray + varInt64 : Result := 'Array of '     + GetTypeName(TypeID - varArray);
     varByRef .. varByRef + varInt64 : Result := 'Reference to ' + GetTypeName(TypeID - varByRef);
     else Result := 'Unknown';
  end;
end;

C++Script, C#Script

function Main()
{
  var TypeID, TypeDescr, Arr;

  TypeID    = GetVarType(255);
  TypeDescr = GetTypeName(TypeID);
  Log["Message"]("Type: " + TypeID + " - " + TypeDescr);
  // Prints "Type: 3 - Signed 32-bit integer"

  TypeID    = GetVarType(aqDateTime["Now"]());
  TypeDescr = GetTypeName(TypeID);
  Log["Message"]("Type: " + TypeID + " - " + TypeDescr);
  // Prints "Type: 7 - Date/Time"        

  Arr       = new Array(1,2,3)
  TypeID    = GetVarType(Arr);
  TypeDescr = GetTypeName(TypeID);
  Log["Message"]("Type: " + TypeID + " - " + TypeDescr);
  // Prints "Type: 9 - Automation object of IDispatch interface"
}

function GetTypeName(TypeID)
{
  var str = "Unknown";
  switch (TypeID)
  {
     case varEmpty :
       str = "Uninitialized";
       break;
     case varNull :
       str = "Null";
       break;
     case varSmallInt :
       str = "Signed 16-bit integer";
       break;
     case varInteger :
       str = "Signed 32-bit integer";
       break;
     case varSingle :
       str = "Single-precision floating-point number";
       break;
     case varDouble :
       str = "Double-precision floating-point number";
       break;
     case varCurrency :
       str = "Currency. High-precision floating-point number";
       break;
     case varDate :
       str = "Date/Time";
       break;
     case varOleStr :
       str = "String";
       break;
     case varDispatch :
       str = "Automation object of IDispatch interface";
       break;
     case varError :
       str = "Code of an OS error";
       break;
     case varBoolean :
       str = "Boolean";
       break;
     case varVariant :
       str = "Variant";
       break;
     case varShortInt :
       str = "Signed 8-bit integer";
       break;
     case varByte :
       str = "Unsigned 8-bit integer";
       break;
     case varWord :
       str = "Unsigned 16-bit integer";
       break;
     case varLongWord :
       str = "Unsigned 32-bit integer";
       break;
     case varInt64 :
       str = "Signed 64-bit integer";
       break;
  }

  if ((TypeID >= varArray) && (TypeID <= varArray + varInt64))
  {
     str = "Array of " + GetTypeName(TypeID - varArray);
  }
  else if ((TypeID >= varByRef) && (TypeID <= varByRef + varInt64))
  {
     str = "Reference to " + GetTypeName(TypeID - varByRef);
  }

  return str;
}

See Also

GetPropertyValue Method
SetPropertyValue Method

Highlight search results