Forum Discussion

erniew's avatar
erniew
New Contributor
13 years ago

Temporary table variables

Temporary table variables are not being stored in Table. This SmartBear example will create a table (1 row and 1 column) if one does not already exist, but no data is written to the table cells.



function TableVarTest()

{

  // Create a table variable if it doesn't exist

  if(!Project.Variables.VariableExists("MyTable"))

    Project.Variables.AddVariable("MyTable", "Table");

  

  // Get a reference to the variable

  var t = Project.Variables.VariableByName("MyTable");

  

  // Add columns to the table

  t.AddColumn("Name");

  t.AddColumn("Age");

  t.AddColumn("City");

  

  // Create two rows

  t.RowCount = 2;



  // Fill in the table

  // The first row

  t.Name(0) = "John Smith";

  t.Age(0) = 24;

  t.City(0) = "Seattle";

  

  // The second row (using the Item property)

  t.Item("Name", 1) = "Bob Feather";

  t.Item("Age", 1) = 59;

  t.Item("City", 1) = "Milltown";

}



I have not been successful in exectuting any script that is able to edit a table variable.



This on version 9.10.1894. Any suggestions are appreciated.

  • erniew's avatar
    erniew
    New Contributor
    I get it now. While the table still exixts, the variables are not retained after the script executes.
  • If you're looking to create tables that are persistent after a script ends I would suggest using Excel and having your script read the Excel file with the DDT.ExcelDriver to fill in your Table Variable.