Hi Lorenzo,
I have fixed the links in my previous post.
I have created a sample script demonstrating how you can work with a Table type variable.
function test()
{
var arr = new Array();
arr["USA"] = "Washington";
arr["UK"] = "London";
arr["India"] = "New Delhi";
for (var i in arr) {
Log.Message(arr);
}
var tbl = copyArrayToTable(arr, "tblVar");
for (var i = 0; i < tbl.rowCount; i++) {
Log.Message(tbl.Item("Key", i) + ": " + tbl.Item("Value", i));
}
Log.Message(getItem("tblVar", "UK"));
}
function copyArrayToTable(arr, tblVarName)
{
if (false == Project.Variables.VariableExists(tblVarName)) {
Project.Variables.AddVariable(tblVarName, "Table");
}
var tbl = Project.Variables.VariableByName(tblVarName);
tbl.RowCount = 0;
while (tbl.ColumnCount > 0) {
tbl.RemoveColumn(0);
tbl.Next();
}
tbl.AddColumn("Key");
tbl.AddColumn("Value");
for (var i in arr) {
addItem(tblVarName, i, arr);
}
return tbl;
}
function addItem(varName, key, value)
{
var tbl = Project.Variables.VariableByName(varName);
tbl.RowCount = tbl.RowCount + 1;
tbl.Item("Key", tbl.RowCount - 1) = key;
tbl.Item("Value", tbl.RowCount - 1) = value;
}
function getItem(varName, key)
{
var tbl = Project.Variables.VariableByName(varName);
var iterator = tbl.Iterator;
while (false == iterator.IsEOF()) {
if (iterator.Value("Key") == key) {
return iterator.Value("Value");
}
iterator.Next();
}
Log.Error("The '" + key + "' item is not found");
return null;
}