BuiltIn.InputBox Method

Applies to TestComplete 15.70, last modified on December 17, 2024

Description

Displays a window with an edit box and two buttons: OK and Cancel. Use this function to quickly get a value from the user.

This method is available if the BuiltIn plugin is installed and enabled. The plugin is installed and enabled by default.

Declaration

BuiltIn.InputBox(Caption, Prompt, Default)

Caption [in]    Required    String    
Prompt [in]    Required    String    
Default [in]    Required    String    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

Caption

The window title.

Prompt

The message that asks the user to enter a value (for instance, "Enter the loop count:").

Default

The string that is displayed in the edit box when the window appears on screen for the first time.

Result Value

If the user presses OK, InputBox will return the entered string. Otherwise, it returns Default.

Example

The following script example demonstrates how you can get a value from a user, and then use it in your script as the default number of rows for a created table variable:

JavaScript, JScript

function TableVarTest()
{
  // Create a table variable if it doesn't exist
  if (!Project.Variables.VariableExists("MyTable"))
  {
    Project.Variables.AddVariable("MyTable", "Table");
  }
  else
  {
    Log.Warning("The MyTable variable already exists. Delete the variable and try again.");
    return;
  }
  // Get a reference to the variable's default value
  var tblVar = Project.Variables.GetVariableDefaultValue("MyTable");
  
  // Add columns to the table
  tblVar.AddColumn("Index");
  tblVar.AddColumn("Name");
  tblVar.AddColumn("Age");
  tblVar.AddColumn("City");
  
  // Show the InputBox message
  var str = BuiltIn.InputBox("InputBox Sample", "Enter the number of rows:", "");
  
  // Initialize table rows
  tblVar.RowCount = aqConvert.StrToInt(str);
  for (var i = 0; i < tblVar.RowCount; i++)
  {
    tblVar.$set("Index", i, i+1);
  }
  Log.Message("The table variable was created successfully with " + str + " rows.");
}

Python

def TableVarTest():
  # Create a table variable if it doesn't exist
  if (not Project.Variables.VariableExists("MyTable")):
    Project.Variables.AddVariable("MyTable", "Table")
  else:
    Log.Warning("The MyTable variable already exists. Delete the variable and try again.")
    return
  # Get a reference to the variable's default value
  tblVar = Project.Variables.GetVariableDefaultValue("MyTable")
  
  # Add columns to the table
  tblVar.AddColumn("Index")
  tblVar.AddColumn("Name")
  tblVar.AddColumn("Age")
  tblVar.AddColumn("City")
  
  # Show the InputBox message
  str = BuiltIn.InputBox("InputBox Sample", "Enter the number of rows:", "")
  
  # Initialize table rows
  tblVar.RowCount = aqConvert.StrToInt(str)
  for i in range (tblVar.RowCount):
    tblVar.Index[i] = i+1
  Log.Message("The table variable was created successfully with " + str + " rows.")

VBScript

Sub TableVarTest
  Dim tblVar, str
  ' Create a table variable if it doesn't exist
  If Not Project.Variables.VariableExists("MyTable") Then
    Call Project.Variables.AddVariable("MyTable", "Table")
  Else
    Log.Warning("The MyTable variable already exists. Delete the variable and try again.")
    Exit Sub
  End If
  
  ' Get a reference to the variable's default value
  Set tblVar = Project.Variables.GetVariableDefaultValue("MyTable")
  
  ' Add columns to the table
  Call tblVar.AddColumn("Index")
  Call tblVar.AddColumn("Name")
  Call tblVar.AddColumn("Age")
  Call tblVar.AddColumn("City")
  
  ' Show the InputBox message
  str = BuiltIn.InputBox("InputBox Sample", "Enter the number of rows:", "")
  
  ' Initialize table rows
  tblVar.RowCount = aqConvert.StrToInt(str)
  For i = 0 To tblVar.RowCount -1
    tblVar.Index(i) = i+1
  Next
  Log.Message("The table variable was created secessfuly with " + str + " rows.")
End Sub

DelphiScript

function TableVarTest;
var tblVar, i, str;
begin

  // Create a table variable if it doesn't exist
  if not Project.Variables.VariableExists('MyTable') then
    Project.Variables.AddVariable('MyTable', 'Table')
  else
  begin
    Log.Warning('The MyTable variable already exists. Delete the variable and try again.');
    exit;
  end;

  // Get a reference to the variable's default value
  tblVar := Project.Variables.GetVariableDefaultValue('MyTable');
  
  // Add columns to the table
  tblVar.AddColumn('Index');
  tblVar.AddColumn('Name');
  tblVar.AddColumn('Age');
  tblVar.AddColumn('City');
  
  // Show the InputBox message
  str := BuiltIn.InputBox('InputBox Sample', 'Enter the number of rows:', '');
  
  // Initialize table rows
  tblVar.RowCount := aqConvert.StrToInt(str);
  for i := 0 to tblVar.RowCount - 1 do
  begin
    tblVar.Index(i) := i+1;
  end;
  Log.Message('The table variable was created successfully with ' + str + ' rows.');
end;

C++Script, C#Script

function TableVarTest()
{
  // Create a table variable if it doesn't exist
  if (!Project["Variables"]["VariableExists"]("MyTable"))
  {
    Project["Variables"]["AddVariable"]("MyTable", "Table");
  }
  else
  {
    Log["Warning"]("The MyTable variable already exists. Delete the variable and try again.");
    return;
  }
  // Get a reference to the variable's default value
  var tblVar = Project["Variables"]["GetVariableDefaultValue"]("MyTable");
  
  // Add columns to the table
  tblVar["AddColumn"]("Index");
  tblVar["AddColumn"]("Name");
  tblVar["AddColumn"]("Age");
  tblVar["AddColumn"]("City");
  
  // Show the InputBox message
  var str = BuiltIn["InputBox"]("InputBox Sample", "Enter the number of rows:", "");
  
 // Initialize table rows
  tblVar["RowCount"] = aqConvert["StrToInt"](str);
  for (var i = 0; i < tblVar["RowCount"]; i++)
  {
    tblVar["Index"](i) = i+1;
  }
  Log["Message"]("The table variable was created successfully with " + str + " rows.");
}

See Also

ShowMessage Method
InputQuery Method
MessageDlg Method

Highlight search results