UserForms.Form Property

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

Use the UserForms.Form property to obtain the UserForm object that provides scripting access to the user form by its index within the list of forms. The total number of the forms in the current project is specified by the FormCount property.

You can also obtain the form by its name, using the FormByName property.

Declaration

UserForms.Form(Index)

Read-Only Property A UserForm object
Index [in]    Required    Integer    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Index

The index of the desired form. The index is zero-based: the form has index 0, the second - 1, and so on. The index of the last form is FormCount - 1.

Property Value

A UserForm object that corresponds to the desired form.

Remarks

If you use Python or DelphiScript, you should enclose the parameter of the Form property in square brackets: Form[Index].

Example

The following example demonstrates how to obtain the user form by its index. The code obtains the form, displays it as a modal dialog and checks which button was pressed to close the 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

FormByName Property
FormCount Property

Highlight search results