Description
The CreateVariantArray
method lets you create a new array whose elements will have the Variant type.
This method is available if the BuiltIn plugin is installed and enabled. The plugin is installed and enabled by default.
Declaration
BuiltIn.CreateVariantArray(Low, High)
Low | [in] | Required | Integer | |
High | [in] | Required | Integer | |
Result | Variant |
Applies To
The method is applied to the following object:
Parameters
The method has the following parameters:
Low
The lowest array index.
High
The highest array index.
Result Value
The created array.
Remarks
The array format adopted in the JavaScript, JScript, Python, C#Script and C++Script languages differs from the format of arrays created with this routine. In these scripting languages, arrays are objects, while the CreateVariantArray
method produces variant arrays. TestComplete supports Python arrays, and there is no need to use variant arrays.
The elements of variant arrays cannot be assigned directly from JavaScript, JScript, C#Script and C++Script. Therefore, you need to create a native Array
object, populate it with values and then convert it to a variant array. To convert an array you can use the following routine:
JavaScript
function ConvertArray(Array)
{
// Uses the Dictionary object to convert an array
var objDict = getActiveXObject("Scripting.Dictionary");
objDict.RemoveAll();
for (i in Array)
objDict.Add(i, Array[i]);
return objDict.Items();
}
JScript
function ConvertArray(Array)
{
// Uses the Dictionary object to convert an array
var objDict = new ActiveXObject("Scripting.Dictionary");
objDict.RemoveAll();
for (var i in Array)
objDict.Add(i, Array[i]);
return objDict.Items();
}
C++Script, C#Script
function ConvertArray(Array)
{
// Uses the Dictionary object to convert a JScript array
var objDict = new ActiveXObject("Scripting.Dictionary");
objDict["RemoveAll"]();
for (var i in JScriptArray)
objDict["Add"](i, JScriptArray[i]);
return objDict["Items"]();
}
To perform the contrary operation, that is, to convert a variant array to JavaScript’s or JScript’s Array
object, call the toArray
method of the variant array. The sample below demonstrates this:
JavaScript, JScript
function Test()
{
var ProcessesVariantArray, ProcessesArray;
ProcessesVariantArray = Sys.FindAll("ProcessName", "*", 1);
// Converting the variant array to the Array object
ProcessesArray = ProcessesVariantArray.toArray();
Log.Message(ProcessesArray[0].ProcessName);
}
C++Script, C#Script
function Test()
{
var ProcessesVariantArray, ProcessesArray;
ProcessesVariantArray = Sys["FindAll"]("ProcessName", "*", 1);
// Converting the variant array to the Array object
ProcessesArray = ProcessesVariantArray["toArray"]();
Log["Message"](ProcessesArray[0]["ProcessName"]);
}
See Also
BuiltIn.CreateVariantArray2 Method
BuiltIn.CreateVariantArray3 Method
BuiltIn.VarArrayRedim Method
BuiltIn.VarArrayLowBound Method
BuiltIn.VarArrayHighBound Method