NameByIndex Method

Applies to TestComplete 15.63, last modified on April 10, 2024

Description

The NameByIndex method lets you obtain the name of the item that has the specified index in the Files, Objects or Regions collection.

Declaration

ProgObj.NameByIndex(Index)

ProgObj An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section
Index [in]    Required    Integer    
Result String

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameter:

Index

Zero-based index of the item whose name in the collection you want to get. To learn the total number of items in the collection, use Count.

Result Value

Unique name of the item with the specified index in the collection.

Example

The following example demonstrates how you can get the names of items of the Files collection and the names of the corresponding stored files.

JavaScript, JScript

function Test1()
{
  var i;

  // Posts the names of the items stored in the Files collection
  Log.Message(Files.NamesList());

  // Posts the names of the files stored in the Files collection
  Log.Message(Files.FileNamesList());

  // Posts the total number of items stored in the Files collection
  Log.Message("The total number of files: " + Files.Count);

  // Iterates through the items of the collection and posts their names and the names of the corresponding files to the log
  for (i = 0; i < Files.Count; i++)
    Log.Message(Files.NameByIndex(i) + " stores " + Files.FileNameByIndex(i));
}

Python

def Test1():
  # Posts the names of the items stored in the Files collection
  Log.Message(Files.NamesList())
  # Posts the names of the files stored in the Files collection
  Log.Message(Files.FileNamesList())
  # Posts the total number of items stored in the Files collection
  Log.Message("The total number of files: " + str(Files.Count))
  # Iterates through the items of the collection and posts their names and the names of the corresponding files to the log
  for i in range(i, Count): 
    Log.Message(Files.NameByIndex[i] + " stores " + Files.FileNameByIndex[i])

VBScript

Sub Test1
  ' Posts the names of the items stored in the Files collection
  Log.Message(Files.NamesList())

  ' Posts the names of the files stored in the Files collection
  Log.Message(Files.FileNamesList())

  ' Posts the total number of items stored in the Files collection
  Log.Message("The total number of files: " & Files.Count)

  ' Iterates through the items of the collection and posts their names and the names of the corresponding files to the log
  For i = 0 To Files.Count-1
    Log.Message(Files.NameByIndex(i) & " stores " & Files.FileNameByIndex(i))
  Next
End Sub

DelphiScript

procedure Test1;
var
  i : OleVariant;
begin
  // Posts the names of the items stored in the Files collection
  Log.Message(Files.NamesList());

  // Posts the names of the files stored in the Files collection
  Log.Message(Files.FileNamesList());

  // Posts the total number of items stored in the Files collection
  Log.Message('The total number of files: ' + Files.Count);

  // Iterates through the items of the collection and posts their names and the names of the corresponding files to the log
  for i := 0 to Files.Count-1 do
    Log.Message(Files.NameByIndex(i) + ' stores ' + Files.FileNameByIndex(i));
end;

C++Script, C#Script

function Test1()
{
  var i;

  // Posts the names of the items stored in the Files collection
  Log["Message"](Files["NamesList"]());

  // Posts the names of the files stored in the Files collection
  Log["Message"](Files["FileNamesList"]());

  // Posts the total number of items stored in the Files collection
  Log["Message"]("The total number of files: " + Files["Count"]);

  // Iterates through the items of the collection and posts their names and the names of the corresponding files to the log
  for (i = 0; i < Files["Count"]; i++)
    Log["Message"](Files["NameByIndex"](i) + " stores " + Files["FileNameByIndex"](i));
}

See Also

Count Method
FileNameByIndex Method
FileNameByName Method
NameByFileName Method
NamesList Method

Highlight search results