Determining the Number of Strings in a Multiline Edit Control

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

When working with an edit control, you may need to know whether it is a single-line or multiline control, and if it is a multiline control you may need to know the number of strings within this control. TestComplete provides a set of built-in routines, including the GetListLength Method routine, that allow you to count the number of strings within the edit control.

While testing edit controls, you can use specific properties and methods of the corresponding program object to perform certain actions and obtain data stored in controls. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with the needed properties and methods from your scripts. However, when testing a control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

Before using this routine you must obtain the edit control’s content. You can do this by using the wText property. Then you can use the aqString.GetListLength routine, which returns a number of items separated with the line breaks. The following example demonstrates how to obtain the number of strings in the edit control:

JavaScript, JScript

function Main()
{
  var p, Edit, Num;
  // Run Notepad
  WshShell.Run("notepad.exe", SW_SHOWNORMAL);
 
  // Obtain the edit object
  p = Sys.Process("NOTEPAD");
  Edit = p.Window("Notepad").Window("Edit");

  Edit.Keys("'What do you know about this business?' the King said to Alice.[Enter]");
  Edit.Keys("'Nothing,' said Alice.[Enter]");
  Edit.Keys("'Nothing WHATEVER?' persisted the King.[Enter]");
  Edit.Keys("'Nothing whatever,' said Alice.[Enter]");
  Edit.Keys("'That's very important,' the King said.");

  // Obtain the number of strings within the control
  Num = aqString.GetListLength(Edit.wText);

  // Post the number of strings to the log
  Log.Message("The number of strings in the text: " + Num);
}

Python

def Main():
  # Run Notepad 
  WshShell.Run("notepad.exe", SW_SHOWNORMAL)
 
  # Obtain the edit object
  p = Sys.Process("NOTEPAD")
  Edit = p.Window("Notepad").Window("Edit")

  Edit.Keys("'What do you know about this business?' the King said to Alice.[Enter]")
  Edit.Keys("'Nothing,' said Alice.[Enter]")
  Edit.Keys("'Nothing WHATEVER?' persisted the King.[Enter]")
  Edit.Keys("'Nothing whatever,' said Alice.[Enter]")
  Edit.Keys("'That's very important,' the King said.")

  # Obtain the number of strings within the control
  Num = aqString.GetListLength(Edit.wText)

  # Post the number of strings to the log
  Log.Message("The number of strings in the text: " + str(Num))

VBScript

Sub Main
  Dim p, Edit, Num
  ' Run Notepad
  Call WshShell.Run("notepad.exe", SW_SHOWNORMAL)

  ' Obtain the edit object
  Set p = Sys.Process("NOTEPAD")
  Set Edit = p.Window("Notepad").Window("Edit")
  Edit.Keys "'What do you know about this business?' the King said to Alice.[Enter]"
  Edit.Keys "'Nothing,' said Alice.[Enter]"
  Edit.Keys "'Nothing WHATEVER?' persisted the King.[Enter]"
  Edit.Keys "'Nothing whatever,' said Alice.[Enter]"
  Edit.Keys "'That's very important,' the King said."

  ' Obtain the number of strings within the control
  Num = aqString.GetListLength(Edit.wText)

  ' Post the number of strings to the log
  Log.Message("The number of strings in the text: " & Num)
End Sub

DelphiScript

procedure Main;
  var p, Edit, Num : OleVariant;
begin
  // Run Notepad
  WshShell.Run('notepad.exe', SW_SHOWNORMAL);
 
  // Obtain the edit object
  p := Sys.Process('NOTEPAD');
  Edit := p.Window('Notepad').Window('Edit');

  Edit.Keys('''What do you know about this business?'' the King said to Alice.[Enter]');
  Edit.Keys('''Nothing,'' said Alice.[Enter]');
  Edit.Keys('''Nothing WHATEVER?'' persisted the King.[Enter]');
  Edit.Keys('''Nothing whatever,'' said Alice.[Enter]');
  Edit.Keys('''That`s very important,'' the King said.');

  // Obtain the number of strings within the control
  Num := aqString.GetListLength(Edit.wText);

  // Post the number of strings to the log
  Log.Message('The number of strings in the text: ' + aqConvert.IntToStr(Num));
end;

C++Script, C#Script

function Main()
{
  var p, Edit, Num;
  // Run Notepad
  WshShell["Run"]("notepad.exe", SW_SHOWNORMAL);
  
  // Obtain the edit object
  p = Sys["Process"]("NOTEPAD");
  Edit = p["Window"]("Notepad")["Window"]("Edit");

  Edit["Keys"]("'What do you know about this business?' the King said to Alice.[Enter]");
  Edit["Keys"]("'Nothing,' said Alice.[Enter]");
  Edit["Keys"]("'Nothing WHATEVER?' persisted the King.[Enter]");
  Edit["Keys"]("'Nothing whatever,' said Alice.[Enter]");
  Edit["Keys"]("'That`s very important,' the King said.");

  // Obtain the number of strings within the control
  Num = aqString["GetListLength"](Edit["wText"]);

  // Post the number of strings to the log
  Log["Message"]("The number of strings in the text: " + Num);
}

See Also

Working With Multiline Edit Controls - Specifics
GetListLength Method
wText Property (Edit Controls)

Highlight search results