UserForms.FormByName Property

Applies to TestComplete 14.93, last modified on October 12, 2021

Description

Use the UserForms.FormByName property to obtain the UserForm object that provides scripting access to the user form by its name.

Declaration

UserForms.FormByName(Name)

Read-Only Property A UserForm object
Name [in]    Required    String    

Applies To

The property is applied to the following object:

Parameters

The property has the following parameter:

Name

Specifies the form name. This is the same value which you see in the corresponding node under the UserForms project item in the Project Explorer panel.

Property Value

A UserForm object that corresponds to the desired form.

Remarks

You can also obtain the form by name via the UserForms object by directly specifying the form name, as follows:

JavaScript, JScript

var form = UserForms.MyForm;

Python

form = UserForms.MyForm

VBScript

Set form = UserForms.MyForm

DelphiScript

var form : OleVariant;
begin
  form := UserForms.MyForm;
end;

C++Script, C#Script

var form = UserForms["MyForm"];

Example

The following example demonstrates how to obtain the user form by its name. It 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 name
  MyTestForm = UserForms.FormByName("UserForm1");
  // 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 name
  MyTestForm = UserForms.FormByName["UserForm1"]
  # 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 name
  Set MyTestForm = UserForms.FormByName("UserForm1")
  ' 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 name
  MyTestForm := UserForms.FormByName('UserForm1');
  // 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 name
  MyTestForm = UserForms["FormByName"]("UserForm1");
  // 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

Form Property
FormCount Property

Highlight search results