Count Method

Applies to TestComplete 14.60, last modified on April 22, 2021

Description

The Count method lets you get the total number of items that belong to the Files, Objects or Regions collection.

Declaration

ProgObj.Count()

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

Applies To

The method is applied to the following objects:

Result Value

The integer that means the number of items 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

NameByIndex Method
FileNameByIndex Method
Contains Method
ContainsFile Method

Highlight search results