GetSubSection Method

Applies to TestComplete 14.20, last modified on September 11, 2019

Description

Use this method to get the Section object for a subsection of the current section. The subsection is identified by its name. To get a list of names of all subsections in the section, use the GetSectionNames method.

If the subsection you want does not exist, the GetSubSection method will create it. You can check if a subsection exists using the SubSectionExists method.

Declaration

ProgObj.GetSubSection(SectionName)

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

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameter:

SectionName

Specifies the name of the desired subsection of the current section.

Result Value

The Section object representing the desired subsection of the current section.

Example

The following code snippet checks whether the subkey exists under the specified registry key. If the subkey does not exist, the code creates it.

JavaScript, JScript

function Test()
{

  var Key, SubKey, SubKeyName;

  // Gets an object for the Windows system registry key
  Key = Storages.Registry("TestKey", HKEY_CURRENT_USER);

  // Specifies the name of the needed subkey
  SubKeyName = "Subkey";

  // Checks whether the specified subkey exists
  if (Key.SubSectionExists(SubKeyName))
    Log.Message("The " + SubKeyName + " subkey exists");
  else
    {
    // If the specified subkey does not exist
    // Creates it under the current registry key
    Log.Warning("The specified subkey does not exist and will be created");
    Key.GetSubSection(SubKeyName);
    }

}

Python

def Test():

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

  # Specifies the name of the needed subkey
  SubKeyName = "Subkey"

  # Checks whether the specified subkey exists
  if (Key.SubSectionExists(SubKeyName)):
    Log.Message("The " + SubKeyName + " subkey exists")
  else:
    # If the specified subkey does not exist
    # Creates it under the current registry key
    Log.Warning("The specified subkey does not exist and will be created")
    Key.GetSubSection(SubKeyName)

VBScript

Sub Test

  Dim Key, SubKey, SubKeyName

  ' Gets an object for the Windows system registry key
  Set Key = Storages.Registry("TestKey", HKEY_CURRENT_USER)

  ' Specifies the name of the needed subkey
  SubKeyName = "Subkey"

  ' Checks whether the specified subkey exists
  If Key.SubSectionExists(SubKeyName) Then
    Log.Message("The " & SubKeyName & " subkey exists")
  Else
    ' If the specified subkey does not exist
    ' Creates it under the current registry key
    Log.Warning("The specified subkey does not exist and will be created")
    Key.GetSubSection(SubKeyName)
  End If

End Sub

DelphiScript

procedure Test();
var Key, SubKey, SubKeyName;

begin

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

  // Specifies the name of the needed subkey
  SubKeyName := 'Subkey';

  // Checks whether the specified subkey exists
  if Key.SubSectionExists(SubKeyName) then
    Log.Message('The ' + SubKeyName + ' subkey exists')
  else
    begin
    // If the specified subkey does not exist
    // Creates it under the current registry key
    Log.Warning('The specified subkey does not exist and will be created');
    Key.GetSubSection(SubKeyName);
    end;

end;

C++Script, C#Script

function Test()
{

  var Key, SubKey, SubKeyName;

  // Gets an object for the Windows system registry key
  Key = Storages["Registry"]("TestKey", HKEY_CURRENT_USER);

  // Specifies the name of the needed subkey
  SubKeyName = "Subkey";

  // Checks whether the specified subkey exists
  if (Key["SubSectionExists"](SubKeyName))
    Log["Message"]("The " + SubKeyName + " subkey exists");
  else
    {
    // If the specified subkey does not exist
    // Creates it under the current registry key
    Log["Warning"]("The specified subkey does not exist and will be created");
    Key["GetSubSection"](SubKeyName);
    }

}

See Also

GetSubSectionByIndex Method
GetSectionName Method
GetOption Method
SubSectionExists Method

Highlight search results