SectionCount Property

Applies to TestComplete 15.40, last modified on July 05, 2022

Description

Use this property to get the number of direct subsections in the current section. This section is specified by the Section object.

Declaration

ProgObj.SectionCount

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

Applies To

The property is applied to the following objects:

Property Value

The number of direct subsections in the current section.

Example

The following code snippet determines how many subkeys the specified registry key contains. After that, it posts the subkey names to the test log.

JavaScript, JScript

function Test()
{

  var Key, Name, SubKey, SubKeyName, Count;
  // Gets an object for the Windows system registry key
  Key = Storages.Registry("TestKey", HKEY_CURRENT_USER, AQRT_32_BIT, true);
  Name = Key.Name;

  // Determines how many keys the current key contains
  Count = Key.SectionCount;

  if (Count > 0)
    {
    Log.AppendFolder("The " + Name + " registry key contains the following subkeys:");
    // Iterates through the keys
    for (var i = 0; i< Count; i++)
      {
      // Obtains the key by its index
      SubKey = Key.GetSubSectionByIndex(i);
      SubKeyName = SubKey.Name;
      // Posts the key name to the test log
      Log.Message(SubKeyName);
      }
    Log.PopLogFolder();
    }

}

Python

def Test():

  # Gets an object for the Windows system registry key
  Key = Storages.Registry("TestKey", HKEY_CURRENT_USER, AQRT_32_BIT, True)
  Name = Key.Name

  # Determines how many keys the current key contains
  Count = Key.SectionCount

  if (Count > 0):
    Log.AppendFolder("The " + Name + " registry key contains the following subkeys:")
    # Iterates through the keys
    for i in range (0, Count):
      # Obtains the key by its index
      SubKey = Key.GetSubSectionByIndex(i)
      SubKeyName = SubKey.Name
      # Posts the key name to the test log
      Log.Message(SubKeyName)
    Log.PopLogFolder()

VBScript

Sub Test

  Dim Key, Name, SubKey, SubKeyName, Count
  ' Gets an object for the Windows system registry key
  Set Key = Storages.Registry("TestKey", HKEY_CURRENT_USER, AQRT_32_BIT, True)
  Name = Key.Name

  ' Determines how many keys the current key contains
  Count = Key.SectionCount

  If Count > 0 Then
    Log.AppendFolder("The " & Name & " registry key contains the following subkeys:")
    ' Iterates through the keys
    For i = 0 To Count - 1

      ' Obtains the key by its index
      Set SubKey = Key.GetSubSectionByIndex(i)
      SubKeyName = SubKey.Name
      ' Posts the key name to the test log
      Log.Message(SubKeyName)
    Next
    Log.PopLogFolder
  End If

End Sub

DelphiScript

procedure Test();
var Key, Name, SubKey, SubKeyName, Count, i;
begin

  // Gets an object for the Windows system registry key
  Key := Storages.Registry('TestKey', HKEY_CURRENT_USER, AQRT_32_BIT, true);
  Name := Key.Name;

  // Determines how many keys the current key contains
  Count := Key.SectionCount;

  if Count > 0 then
    begin
    Log.AppendFolder('The ' + Name + ' registry key contains the following subkeys:');
    // Iterates through the keys
    for i := 0 to Count - 1 do
      begin
      // Obtains the key by its index
      SubKey := Key.GetSubSectionByIndex(i);
      SubKeyName := SubKey.Name;
      // Posts the key name to the test log
      Log.Message(SubKeyName);
      end;
    Log.PopLogFolder;
    end;

end;

C++Script, C#Script

function Test()
{

  var Key, Name, SubKey, SubKeyName, Count;
  // Gets an object for the Windows system registry key
  Key = Storages["Registry"]("TestKey", HKEY_CURRENT_USER, AQRT_32_BIT, true);
  Name = Key["Name"];

  // Determines how many keys the current key contains
  Count = Key["SectionCount"];

  if (Count > 0)
    {
    Log["AppendFolder"]("The " + Name + " registry key contains the following subkeys:");
    // Iterates through the keys
    for (var i = 0; i< Count; i++)
      {
      // Obtains the key by its index
      SubKey = Key["GetSubSectionByIndex"](i);
      SubKeyName = SubKey["Name"];
      // Posts the key name to the test log
      Log["Message"](SubKeyName);
      }
    Log["PopLogFolder"]();
    }

}

See Also

Name Property
OptionCount Property
SubSectionExists Method

Highlight search results