UserForms Object

Applies to TestComplete 15.20, last modified on January 19, 2022

Description

The UserForms object provides scripting access to user forms included in the current TestComplete project. This object is only available if your project contains the User Forms Project Item.

For each user form displayed in the Project Explorer panel under the UserForms node, the UserForms object provides a property with the same name, which provides scripting access to the corresponding form. You can use the resulting UserForm object to work with the form, for example, display or hide it, access its components and so on.

The UserForms object has additional properties that let you enumerate the forms.

Members

Example

The following example demonstrates how to obtain the user form.

JavaScript, JScript

function Test()
{
  var MyTestForm, mr;
  // Obtains the user form by its index
  MyTestForm = UserForms.Form(0);
  // Displays the form as a modal dialog
  mr = MyTestForm.ShowModal();

  // Checks which form button was pressed
  if (mr == mrOK)
    ShowMessage("The OK button was pressed");
  else
    ShowMessage("The Cancel button was pressed");

}

Python

def Test():
  # Obtains the user form by its index 
  MyTestForm = UserForms.Form[0]
  # Displays the form as a modal dialog 
  mr = MyTestForm.ShowModal()
  # Checks which form button was pressed 
  if mr == mrOK:
    ShowMessage("The OK button was pressed")
  else:
    ShowMessage("The Cancel button was pressed")

VBScript

Sub Test

  Dim MyTestForm, mr
  ' Obtains the user form by its index
  Set MyTestForm = UserForms.Form(0)
  ' Displays the form as a modal dialog
  mr = MyTestForm.ShowModal

  ' Checks which form button was pressed
  If mr = mrOK Then
    ShowMessage "The OK button was pressed"
  Else
    ShowMessage "The Cancel button was pressed"
  End If

End Sub

DelphiScript

procedure Test();
var MyTestForm, mr;
begin
  // Obtains the user form by its index
  MyTestForm := UserForms.Form[0];
  // Displays the form as a modal dialog
  mr := MyTestForm.ShowModal;

  // Checks which form button was pressed
  if mr = mrOK then
    ShowMessage('The OK button was pressed')
  else
    ShowMessage('The Cancel button was pressed');

end;

C++Script, C#Script

function Test()
{
  var MyTestForm, mr;
  // Obtains the user form by its index
  MyTestForm = UserForms["Form"](0);
  // Displays the form as a modal dialog
  mr = MyTestForm["ShowModal"]();

  // Checks which form button was pressed
  if (mr == mrOK)
    ShowMessage("The OK button was pressed");
  else
    ShowMessage("The Cancel button was pressed");

}

See Also

User Forms
UserForm Object

Highlight search results