SubSectionExists Method

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

Description

This method returns True if a section belongs to the subsection list of the current section. Else, it returns False. The subsection is identified by its name. To get a list of names for all subsections in the section, use the GetSectionNames method.

Declaration

ProgObj.SubSectionExists(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 Boolean

Applies To

The method is applied to the following objects:

Parameters

The method has the following parameter:

SectionName

Specifies the name of the subsection whose existence you want to obtain.

Result Value

If the specified subsection belongs to the current section, the method returns True. Else, it returns False.

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

SectionCount Property
OptionExists Method
GetSectionName Method
GetSectionNames Method

Highlight search results