OptionCount Property

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

Use this property to get the number of options in the current section. This section is specified by the Section or FileSection object. The options are counted in the current section only, not in its subsections.

Declaration

ProgObj.OptionCount

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 options in the current section.

Remarks

If the ProgObj object corresponds to a registry key, the OptionCount property value does not include the option marked as (Default). This is because all registry keys have this option.

Example

The following code snippet determines how many values the registry key contains. After that, it iterates through the values and posts them to the test log.

JavaScript, JScript

function Test()
{

  var Key, Name, Count, ValueName, Value;

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

  // Determines how many values the key contains
  Count = Key.OptionCount;
  if (Count > 0)
    {
    Log.AppendFolder("The" + Name + " registry key contains the following values:");

    // Iterates through the values
    for (var i = 0; i < Count; i++)
      {
      // Obtains the name of the value
      ValueName = Key.GetOptionName(i);
      // Obtains the value
      Value = Key.GetOption(ValueName, "not specified");
      // Posts the value to the test log
      Log.Message(ValueName + ": " + Value);
      }
    Log.PopLogFolder();
    }

}

Python

def Test():

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

  # Determines how many values the key contains
  Count = Key.OptionCount
  if (Count > 0):
    Log.AppendFolder("The" + Name + " registry key contains the following values:")

    # Iterates through the values
    for i in range (0, Count):
      # Obtains the name of the value
      ValueName = Key.GetOptionName(i)
      # Obtains the value
      Value = Key.GetOption(ValueName, "not specified")
      # Posts the value to the test log
      Log.Message(ValueName + ": " + str(Value))
    Log.PopLogFolder()

VBScript

Sub Test

  Dim Key, Name, Count, ValueName, Value

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

  ' Determines how many values the key contains
  Count = Key.OptionCount
  If Count > 0 Then
    Log.AppendFolder("The" & Name & " registry key contains the following values:")

    ' Iterates through the values
    For i = 0 To Count - 1
      ' Obtains the name of the value
      ValueName = Key.GetOptionName(i)
      ' Obtains the value
      Value = Key.GetOption(ValueName, "not specified")
      ' Posts the value to the test log
      Log.Message(ValueName & ": " & Value)
    Next
    Log.PopLogFolder
  End If

End Sub

DelphiScript

procedure Test();
var Key, Name, Count, ValueName, Value, i;

begin

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

  // Determines how many values the key contains
  Count := Key.OptionCount;
  if Count > 0 then
    begin
    Log.AppendFolder('The' + Name + ' registry key contains the following values:');

    // Iterates through the values
    for i := 0 to Count - 1 do
      begin
      // Obtains the name of the value
      ValueName := Key.GetOptionName(i);
      // Obtains the value
      Value := Key.GetOption(ValueName, 'not specified');
      // Posts the value to the test log
      Log.Message(ValueName + ': ' + aqConvert.VarToStr(Value));
      end;
    Log.PopLogFolder;
    end;

end;

C++Script, C#Script

function Test()
{

  var Key, Name, Count, ValueName, Value;

  // Gets an object for a Windows system registry key
  Key = Storages["Registry"]("TestKey\\Subkey", HKEY_CURRENT_USER, AQRT_32_BIT, true);
  Name = Key["Name"];

  // Determines how many values the key contains
  Count = Key["OptionCount"];
  if (Count > 0)
    {
    Log["AppendFolder"]("The" + Name + " registry key contains the following values:");

    // Iterates through the values
    for (var i = 0; i < Count; i++)
      {
      // Obtains the name of the value
      ValueName = Key["GetOptionName"](i);
      // Obtains the value
      Value = Key["GetOption"](ValueName, "not specified");
      // Posts the value to the test log
      Log["Message"](ValueName + ": " + Value);
      }
    Log["PopLogFolder"]();
    }

}

See Also

Name Property
OptionExists Method
SectionCount Property

Highlight search results