ColumnByName Property

Applies to TestComplete 14.0, last modified on January 23, 2019

Description

The ColumnByName property lets you obtain a table column by its name. You can then use the resulting LogColumn object when obtaining values stored in the table cells.

You can also obtain the desired column by its index using the Column property. To get the total number of columns in the table, use the ColumnCount property.

Declaration

LogTableDataSchemeObj.ColumnByName(AName)

Read-Only Property A LogColumn object
LogTableDataSchemeObj An expression, variable or parameter that specifies a reference to a LogTableDataScheme object
AName [in]    Required    String    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

AName

The name of the desired column. This is the same string that you see in the column header of the test log.

Property Value

A LogColumn object corresponding to the desired table column.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the ColumnByName property in square brackets: ColumnByName[AName].

Example

The code below obtains the data type of the Message column.

JavaScript, JScript

function LogColumn()
{
  // Obtains a collection of logs
  var LogsCol = Project.Logs;
  // Obtains the first log item
  var LogItem = LogsCol.LogItem(0);
  // Obtains the first dataset
  // of the specified log item
  var LogData = LogItem.Data(0);
  // Obtains the scheme of the dataset
  var Sch = LogData.Scheme;
  // Obtains information about the third column
  var Column = Sch.ColumnByName("Message");
  Log.Message("The Message column contains the following data:");
  
  // Obtains the data type of the Message column
  switch (Column.DataType)
  {
    case ctInteger:
    {
      Log.Message("integer numbers");
      break;
    }
    case ctString:
    {
      Log.Message("strings");
      break;
    }
    case ctFloat:
    {
      Log.Message("floating-point numbers");
      break;
    }
    case ctBoolean:
    {
      Log.Message("boolean values");
      break;
    }
    case ctImage:
    {
      Log.Message("images");
      break;
    }
    case ctHyperlink:
    {
      Log.Message("hyperlinks");
      break;
    }
    case ctDateTime:
    {
      Log.Message("date or time values");
      break;
    }
  }
}

Python

def LogColumn():
  # Obtains a collection of logs
  LogsCol = Project.Logs
  # Obtains the first log item
  LogItem = LogsCol.LogItem[0]
  # Obtains the first dataset
  # of the specified log item
  LogData = LogItem.Data[0]
  # Obtains the scheme of the dataset
  Sch = LogData.Scheme
  # Obtains information about the third column
  Column = Sch.ColumnByName["Message"]
  Log.Message("The Message column contains the following data:")
  # Obtains the data type of the Message column
  if Column.DataType == ctInteger:
    Log.Message("integer numbers")
  elif Column.DataType == ctString:
    Log.Message("strings")
  elif Column.DataType == ctFloat:
    Log.Message("floating-point numbers")
  elif Column.DataType == ctBoolean:
    Log.Message("boolean values")
  elif Column.DataType == ctImage:
    Log.Message("images")
  elif Column.DataType == ctHyperlink:
    Log.Message("hyperlinks");
  elif Column.DataType == ctDateTime:
    Log.Message("date or time values")

VBScript

Sub LogColumn()

  ' Obtains a collection of logs
  Set LogsCol = Project.Logs
  ' Obtains the first log item
  Set LogItem = LogsCol.LogItem(0)
  ' Obtains the first dataset
  ' of the specified log item
  Set LogData = LogItem.Data(0)
  ' Obtains the scheme of the dataset
  Set Sch = LogData.Scheme
  ' Obtains information about the Message column
  Set Column = Sch.ColumnByName("Message")
  Log.Message("The Message column contains the following data:")
  
  ' Obtains the data type of the Message column
  Select case Column.DataType
    case ctInteger: Log.Message("integer numbers")
    case ctString: Log.Message("strings")
    case ctFloat: Log.Message("floating-point numbers")
    case ctBoolean: Log.Message("boolean values")
    case ctImage: Log.Message("images")
    case ctHyperlink: Log.Message("hyperlinks")
    case ctDateTime: Log.Message("date or time values")
  End Select
 
End Sub

DelphiScript

function LogColumn;
var LogsCol, LogItem, LogData, Sch, Column, Name;
begin

  // Obtains a collection of logs
  LogsCol := Project.Logs;
  // Obtains the first log item
  LogItem := LogsCol.LogItem(0);
  // Obtains the first dataset
  // of the specified log item
  LogData := LogItem.Data(0);
  // Obtains the scheme of the dataset
  Sch := LogData.Scheme;
  // Obtains information about the third column
  Column := Sch.ColumnByName('Message');
  Log.Message('The Message column contains the following data:');
  
  // Obtains the data type of the Message column
  case Column.DataType of
    ctInteger: Result : = Log.Message('integer numbers');
    ctString: Result := Log.Message('strings');
    ctFloat: Result := Log.Message('floating-point numbers');
    ctBoolean: Result := Log.Message('boolean values');
    ctImage: Result := Log.Message('images');
    ctHyperlink: Result := Log.Message('hyperlinks');
    ctDateTime: Result := Log.Message('date or time values');
  end;

end;

C++Script, C#Script

function LogColumn()
{
  // Obtains a collection of logs
  var LogsCol = Project["Logs"];
  // Obtains the first log item
  var LogItem = LogsCol["LogItem"](0);
  // Obtains the first dataset
  // of the specified log item
  var LogData = LogItem["Data"](0);
  // Obtains the scheme of the dataset
  var Sch = LogData["Scheme"];
  // Obtains information about the third column
  var Column = Sch["ColumnByName"]("Message");
  Log["Message"]("The Message column contains the following data:");
  
  // Obtains the data type of the Message column
  switch (Column["DataType"])
  {
    case ctInteger:
    {
      Log["Message"]("integer numbers");
      break;
    }
    case ctString:
    {
      Log["Message"]("strings");
      break;
    }
    case ctFloat:
    {
      Log["Message"]("floating-point numbers");
      break;
    }
    case ctBoolean:
    {
      Log["Message"]("boolean values");
      break;
    }
    case ctImage:
    {
      Log["Message"]("images");
      break;
    }
    case ctHyperlink:
    {
      Log["Message"]("hyperlinks");
      break;
    }
    case ctDateTime:
    {
      Log["Message"]("date or time values");
      break;
    }
  }
}

See Also

Access Test Log Contents from Tests
Column Property
ColumnCount Property
LogColumn Object

Highlight search results