Tom_Welch
12 years agoNew Contributor
aqObject.GetVarType does not work correctly with arrays?
I have read the help page at this address: http://support.smartbear.com/viewarticle/57577/
It says that I can use the GetVarType method on aqObject to return a number indicating what variable type I am using. The table at the top of the page says:
However, in the code example given it says:
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
But this is clearly not the desired return value. I need to distinguish whether or
not I have been passed an array froma basic IDispatch implementing object. I
have tried the following code, but to no avail:
function TestGetType()
{
var arr = new Array("s", "c");
var type = GetVarType(arr);
Log.Message(type);//=> 9 (Automation object of IDispatch interface - wrong)
arr = [1, 2, 3];
type = GetVarType(arr);
Log.Message(type);//=> 9 (Automation object of IDispatch interface - wrong)
var str = "Hi";
type = GetVarType(str);
Log.Message(type);//=> 8 (OleStr - Correct!)
var num = 1234.12
type = GetVarType(num);
Log.Message(type);//=> 5 (Double - Correct!)
}
How do I actually check to make sure that a variable is in fact an array?
It says that I can use the GetVarType method on aqObject to return a number indicating what variable type I am using. The table at the top of the page says:
varArray | 2000h | 8192 | Array. Type of array elements is specified by the lower bits. For example, 2003h is an array of integers. |
However, in the code example given it says:
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
But this is clearly not the desired return value. I need to distinguish whether or
not I have been passed an array froma basic IDispatch implementing object. I
have tried the following code, but to no avail:
function TestGetType()
{
var arr = new Array("s", "c");
var type = GetVarType(arr);
Log.Message(type);//=> 9 (Automation object of IDispatch interface - wrong)
arr = [1, 2, 3];
type = GetVarType(arr);
Log.Message(type);//=> 9 (Automation object of IDispatch interface - wrong)
var str = "Hi";
type = GetVarType(str);
Log.Message(type);//=> 8 (OleStr - Correct!)
var num = 1234.12
type = GetVarType(num);
Log.Message(type);//=> 5 (Double - Correct!)
}
How do I actually check to make sure that a variable is in fact an array?