GetSubSectionByIndex Method

Applies to TestComplete 15.69, last modified on November 13, 2024

Description

Use this method to get the Section object for a subsection of the current section. The subsection is identified by its index in the subsection collection of the current section. To get the number of subsections in this collection, use the SectionCount property. If the subsection you want does not exist, an error occurs.

Declaration

ProgObj.GetSubSectionByIndex(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 A Section object

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameter:

Index

Specifies the index of the desired subsection. The index is zero-based, that is, the first subsection has index 0, the second - 1, and so on. Index of the last subsection is SectionCount-1.

Result Value

The Section object representing the desired subsection of 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

GetSubSection Method
SectionCount Property
GetOptionByIndex Method

Highlight search results