Calling Script Routines via COM

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

This topic describes how you can command TestComplete to run a script routine by name. Before you continue, we recommend that you read the Working With TestComplete via COM topic that provides detailed information on working with the TestComplete engine via COM.

To call a script routine via COM, you should use the RunRoutine or RunRoutineEx methods of the Integration object (for more information on these methods and the object, see Working With TestComplete via COM). The difference between the methods are that RunRoutineEx lets you call routines containing parameters, while RunRoutine can only call script functions that do not use parameters. In other words, RunRoutine is a simpler variant of RunRoutineEx. Both methods can be used to call script routines that return values.

Note: In order for TestComplete to be able to call these routines, the test must not be running. That is, a call to RunRoutine or RunRoutineEx will fail if TestComplete is running tests at the moment of the call. In order to check whether a test is running, use the IsRunning property of the TestComplete Integration object.

The declarations of the RunRoutine and RunRoutineEx methods are very similar:

RunRoutine(ProjectName, UnitName, RoutineName)

RunRoutineEx(ProjectName, UnitName, RoutineName, Parameters)

  • ProjectName - Name of the TestComplete project holding the routine. To execute the routine, this project must be loaded in TestComplete.
  • UnitName - Name of the script unit that holds the routine to be called and that belongs to the project specified by ProjectName.
  • RoutineName - Name of the desired routine.
  • Parameters - An OLE Variant-compatible array of the parameters passed to the script routine.

Both functions do not pause the program execution until the run of the specified script routine is over. To obtain the routine result, use the RoutineResult property of the TestComplete Integration object.

If by some reason the use of RunRoutineEx is not possible, you can pass parameters through a temporary location: file, database, clipboard, properties of a COM object, and so on. For example, you can --

  • Write the desired data to a small file and then add the code, that will retrieve data from this file, to your script routine called via COM.

  • Store data to the clipboard, write the script code that will parse the clipboard data and execute this code at the beginning of the script routine called via COM.

  • And so on.

The following example demonstrates how you can call a script routine from a Visual Basic or C# application using the RunRoutine and RunRoutineEx functions.

RunRoutine Example

The following sample demonstrates how to call a script routine from a Visual Basic or C# application. The sample code passes parameters via a temporary file. The sample code of the called script routine follows these samples. Note that C# does not allow performing certain actions with objects defined at runtime. For example, you cannot use the switch statement to check object properties.

Visual Basic

Sub MySub
  ' Initialize variables
  sProjectNameFileName = "C:\Work\MyProject\MyProjectSuite.pjs"
  sProjectName = "TestProject"
  sUnitName = "Unit1"
  sRoutineName = "MyRoutine"

  ' Creates the application object
  Set TestCompleteApp = CreateObject("TestComplete.TestCompleteApplication.14")

  ' Obtains the integration object
  Set IntegrationObject = TestCompleteApp.Integration

  ' Opens the project
  IntegrationObject.OpenProjectSuiteEx sProjectNameFileName

  ' Saves data to a temporary file
  Set FSO = CreateObject("Scripting.FileSystemObject")
  Set MyFile = FSO.OpenTextFile("C:\TempFile.txt", 2, True) ' Open for writing
  MyFile.WriteLine "John Smith,[email protected],05/05/2009,0000-1234-5678-9000"
  MyFile.Close

  ' Needed to process errors
  Err.Clear
  On Error GoTo Err_Label

  ' Runs the routine
  IntegrationObject.RunRoutine sProjectName, sUnitName, sRoutineName

  ' Waits until the test run is over
  While IntegrationObject.IsRunning
    DoEvents
  Wend

  ' Check the results
  If aqObject.GetVarType(IntegrationObject.RoutineResult) <> vbEmpty Then
    MsgBox "Script routine returned " + IntegrationObject.RoutineResult
  Else
    MsgBox "Script routine result did not return any result"
  End If

  Set LastResult = IntegrationObject.GetLastResultDescription
  Select Case LastResult.Status
    Case 0: MsgBox "The test run finished successfully."
    Case 1: MsgBox "Warning messages were posted to the test log."
    Case 2: MsgBox "Error messages were posted to the test log."
  End Select

Err_Label:
  ' Process errors
  If Err.Number <> 0 Then
    MsgBox "Cannot start the test. Reason: " + Err.Description, vbCritical, "Error"
  End If

  ' Quits TestComplete
  TestCompleteApp.Quit
End Sub

Visual C# Early Binding

// Add the following lines to your unit
using System.Runtime.InteropServices;
using TestComplete;

...

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Invokes TestComplete upon a button click
            TestFunc();
        }

        private void TestFunc()
        {
            const string TCProgID = "TestComplete.TestCompleteApplication.14";
            object TestCompleteObject = null;

            // Initialize variables
            string sProjectFileName = "C:\\Work\\MyProject\\MyProjectSuite.pjs";
            string sProjectName = "TestProject";
            string sUnitName = "Unit1";
            string sRoutineName = "MyRoutine";

            // Obtains access to TestComplete
            try
            {
                TestCompleteObject = Marshal.GetActiveObject(TCProgID);
            }
            catch
            {
                try
                {
                    TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
                }
                catch
                {
                }
            }

            if (TestCompleteObject == null) return;


            // Obtain the ITestCompleteCOMManager object
            TestComplete.ITestCompleteCOMManager TestCompleteManager = (TestComplete.ITestCompleteCOMManager)TestCompleteObject;
            // Obtain the Integration object
            TestComplete.ItcIntegration IntegrationObject = TestCompleteManager.Integration;

            // We have a reference to the integration object.
            // Now we can use its methods and properties to automate TestComplete.

            // Loads the project suite
            IntegrationObject.OpenProjectSuiteEx(sProjectFileName);

        // Save data to a temporary file
        System.IO.StreamWriter MyFile = new System.IO.StreamWriter("C:\\TempFile.txt");
        MyFile.WriteLine("John Smith,[email protected],05/05/2009,0000-1234-5678-9000");
        MyFile.Close();

            try
            {
                // Runs the routine
                IntegrationObject.RunRoutine(sProjectName, sUnitName, sRoutineName);

                // Waits until testing is over
                while (IntegrationObject.IsRunning())
                    Application.DoEvents();

                // Check the results
                object RoutineResult = IntegrationObject.RoutineResult;
                if (RoutineResult != null)
                    System.Windows.Forms.MessageBox.Show("Script routine returned " + RoutineResult.ToString());
                else
                    System.Windows.Forms.MessageBox.Show("Script routine did not return any result");

            switch (IntegrationObject.GetLastResultDescription().Status)
            {
                case TestComplete.TC_LOG_STATUS.lsOk:
                    System.Windows.Forms.MessageBox.Show(this, "The test run finished successfully.");
                   break;
                case TestComplete.TC_LOG_STATUS.lsWarning:
                    System.Windows.Forms.MessageBox.Show(this, "Warning messages were posted to the test log.");
                    break;
                case TestComplete.TC_LOG_STATUS.lsError:
                    System.Windows.Forms.MessageBox.Show(this, "Error messages were posted to the test log.");
                    break;
            }

            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message);
            }
            finally
            {
                // Closes TestComplete
                TestCompleteManager.Quit();
                // Releases COM objects
                Marshal.ReleaseComObject(IntegrationObject);
                Marshal.ReleaseComObject(TestCompleteManager);
                Marshal.ReleaseComObject(TestCompleteObject);
            }
        }
    }

Visual C# Late Binding

// Add the following lines to your unit
using System.Runtime.InteropServices;
using TestComplete;

...

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Invokes TestComplete upon a button click
            TestFunc();
        }

        private void TestFunc()
        {
            const string TCProgID = "TestComplete.TestCompleteApplication.14";
            dynamic TestCompleteObject = null;

            // Initialize variables
            string sProjectFileName = "C:\\Work\\MyProject\\MyProjectSuite.pjs";
            string sProjectName = "TestProject";
            string sUnitName = "Unit1";
            string sRoutineName = "MyRoutine";

            // Obtains access to TestComplete
            try
            {
                TestCompleteObject = Marshal.GetActiveObject(TCProgID);
            }
            catch
            {
                try
                {
                    TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
                }
                catch
                {
                }
            }

            if (TestCompleteObject == null) return;


            // Obtains Integration object during runtime
            dynamic IntegrationObject = TestCompleteObject.Integration;

            // We have a reference to the integration object.
            // Now we can use its methods and properties to automate TestComplete.

            // Loads the project suite
            IntegrationObject.OpenProjectSuiteEx(sProjectFileName);

        // Save data to a temporary file
        System.IO.StreamWriter MyFile = new System.IO.StreamWriter("C:\\TempFile.txt");
        MyFile.WriteLine("John Smith,[email protected],05/05/2009,0000-1234-5678-9000");
        MyFile.Close();

            try
            {
                // Runs the routine
                IntegrationObject.RunRoutine(sProjectName, sUnitName, sRoutineName);

                // Waits until testing is over
                while (IntegrationObject.IsRunning())
                    Application.DoEvents();

                // Check the results
                object RoutineResult = IntegrationObject.RoutineResult;
                if (RoutineResult != null)
                    System.Windows.Forms.MessageBox.Show("Script routine returned " + RoutineResult.ToString());
                else
                    System.Windows.Forms.MessageBox.Show("Script routine did not return any result");


                if (IntegrationObject.GetLastResultDescription().Status == 0)
                {
                    System.Windows.Forms.MessageBox.Show(this, "The test run finished successfully.");
                }
                if (IntegrationObject.GetLastResultDescription().Status == 1)
                {
                    System.Windows.Forms.MessageBox.Show(this, "Warning messages were posted to the test log.");
                }
                if (IntegrationObject.GetLastResultDescription().Status == 2)
                {
                    System.Windows.Forms.MessageBox.Show(this, "Error messages were posted to the test log.");
                }

            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message);
            }
            finally
            {
                // Closes TestComplete
                TestCompleteManager.Quit();
                // Releases COM objects
                Marshal.ReleaseComObject(IntegrationObject);
                Marshal.ReleaseComObject(TestCompleteObject);
            }
        }
    }

Here is a sample script that is run via COM. The above Visual Basic or C# code calls the MyRoutine procedure, which in turn calls the ReadData function to read data from a file:

JavaScript

function ReadData()
{
  let ForReading, FSO, MyFile, Cnt, Data, s;

  // Open the file
  ForReading = 1;
  FSO = getActiveXObject("Scripting.FileSystemObject");
  MyFile = FSO.OpenTextFile("C:\\TempFile.txt", ForReading, false);

  // Read data from the file
  s = MyFile.ReadLine(); // We use only one line of data

  // Obtains data and stores them to an array
  aqString.ListSeparator = ",";
  Cnt = aqString.GetListLength(s);
  Data = new Array(Cnt + 1);
  Data[0] = Cnt;
  for(let i = 0; i < Cnt; i++)
    Data[i + 1] = aqString.GetListItem(s, i);

  // Close the file
  MyFile.Close();

  // Returns the result
  return Data;
}

function MyRoutine()
{
  let Data, s;

  // Obtains data
  Data = ReadData();

  // Work with data
  s = "";
  for(let i = 1; i <= Data[0]; i++)
  {
    Log.Message(Data[i]);
    s = s + Data[i] + ", ";
  }
  return s;
}

JScript

function ReadData()
{
  var ForReading, FSO, MyFile, Cnt, i, Data, s;

  // Open the file
  ForReading = 1;
  FSO = new ActiveXObject("Scripting.FileSystemObject");
  MyFile = FSO.OpenTextFile("C:\\TempFile.txt", ForReading, false);

  // Read data from the file
  s = MyFile.ReadLine(); // We use only one line of data

  // Obtains data and stores them to an array
  aqString.ListSeparator = ",";
  Cnt = aqString.GetListLength(s);
  Data = new Array(Cnt + 1);
  Data[0] = Cnt;
  for(i = 0; i < Cnt; i++)
    Data[i + 1] = aqString.GetListItem(s, i);

  // Close the file
  MyFile.Close();

  // Returns the result
  return Data;
}

function MyRoutine()
{
  var Data, i, s;

  // Obtains data
  Data = ReadData();

  // Work with data
  s = "";
  for(i = 1; i <= Data[0]; i++)
  {
    Log.Message(Data[i]);
    s = s + Data[i] + ", ";
  }
  return s;
}

Python

def ReadData():
  # Open the file
  ForReading = 1;
  FSO = Sys.OleObject["Scripting.FileSystemObject"];
  MyFile = FSO.OpenTextFile("C:\\TempFile.txt", ForReading, False); 
  # Read data from the file
  s = MyFile.ReadLine(); # We use only one line of data

  # Obtains data and stores them to an array
  aqString.ListSeparator = ",";
  Cnt = aqString.GetListLength(s);
  Data = [];
  Data.append(Cnt);
  for i in range (0, Cnt):
    Data.append(aqString.GetListItem(s, i));

  # Close the file
  MyFile.Close(); 
  # Returns the result
  return Data;

def MyRoutine():
  # Obtains data
  Data = ReadData();

  # Work with data
  s = "";
  for i in range (1, Data[0]+1):
    Log.Message(Data[i]);
    s = s + aqConvert.VarToStr(Data[i]) + ', ';
  return s;

VBScript

Function ReadData
  ' Open file
  ForReading = 1
  Set FSO = CreateObject("Scripting.FileSystemObject")
  Set MyFile = FSO.OpenTextFile("C:\TempFile.txt", ForReading, False)

  ' Read data from the file
  s = MyFile.ReadLine ' We use only one line of data

  ' Obtains data and stores them to an array
  aqString.ListSeparator = ","
  Cnt = aqString.GetListLength(s)
  ReDim Data(Cnt + 1)
  Data(0) = Cnt
  For i = 0 To Cnt - 1
    Data(i + 1) = aqString.GetListItem(s, i)
  Next

  ' Close the file
  MyFile.Close

  ' Returns the result
  ReadData = Data
End Function

Function MyRoutine
  ' Obtains data
  Data = ReadData

  ' Work with data
  MyRoutine = ""
  For i = 1 To Data(0)
    Log.Message Data(i)
    MyRoutine = MyRoutine & Data(i) & ", "
  Next
End Function

DelphiScript

function ReadData();
var
  ForReading, FSO, MyFile, Cnt, i, Data, s : OleVariant;
begin
  // Open the file
  ForReading := 1;
  FSO := Sys.OleObject('Scripting.FileSystemObject');
  MyFile := FSO.OpenTextFile('C:\TempFile.txt', ForReading, false);
  // Read data from the file
  s := MyFile.ReadLine(); // We use only one line of data

  // Obtains data and stores them to an array
  aqString.ListSeparator := ',';
  Cnt := aqString.GetListLength(s);
  Data := BuiltIn.CreateVariantArray(0, Cnt + 1);   Data[0] := Cnt;
  for i := 0 to Cnt - 1 do
    Data[i + 1] := aqString.GetListItem(s, i);

  // Close the file
  MyFile.Close();
  // Returns the result
  Result := Data;
end;

function MyRoutine();
var
  Data, i : OleVariant;
begin
  // Obtains data
  Data := ReadData();

  // Work with data
  Result := '';
  for i := 1 to Data[0] do
  begin
    Log.Message(Data[i]);
    Result := Result + aqConvert.VarToStr(Data[i]) + ', ';
  end;
end;

C++Script, C#Script

function ReadData()
{
  var ForReading, FSO, MyFile, Cnt, i, Data;

  // Open the file
  ForReading = 1;
  FSO = new ActiveXObject("Scripting.FileSystemObject");
  MyFile = FSO["OpenTextFile"]("C:\\TempFile.txt", ForReading, false);
  // Read data from the file
  s = MyFile["ReadLine"](); // We use only one line of data

  // Obtains data and stores them to an array
  aqString["ListSeparator"] = ",";
  Cnt = aqString["GetListLength"](s);
  Data = new Array(Cnt + 1);
  Data[0] = Cnt;
  for(i = 0; i < Cnt; i++)
    Data[i + 1] = aqString["GetListItem"](s, i);

  // Close the file
  MyFile["Close"]();

  // Returns the result
  return Data;
}

function MyRoutine()
{
  var Data, i, s;

  // Obtains data
  Data = ReadData();

  // Work with data
  s = "";
  for(i = 1; i <= Data[0]; i++)
  {
    Log["Message"](Data[i]);
    s = s + aqConvert["VarToStr"](Data[i]) + ", ";
  }
  return s;
}

RunRoutineEx Example

The following sample demonstrates how to call a script routine from a Visual Basic or C# application using the RunRoutineEx method. The sample code of the called script routine follows the VB and C# samples:

Visual Basic

Sub MySub()
  Dim ParamArr(3)

  ' Initialize variables
  sProjectNameFileName = "C:\MyProjects\MyProject\MyProject.mds"
  sProjectName = "MyProject"
  sUnitName = "Unit1"
  sRoutineName = "MyRoutine"

  ParamArr(0) = "John Smith"
  ParamArr(1) = "[email protected]"
  ParamArr(2) = "5/5/2009"
  ParamArr(3) = "0000-1234-5678-9000"
  
  ' Creates the application object
  Set TestCompleteApp = CreateObject("TestComplete.TestCompleteApplication.14")

  ' Obtains the integration object
  Set IntegrationObject = TestCompleteApp.Integration

  ' Opens the project
  IntegrationObject.OpenProjectSuiteEx sProjectNameFileName

   ' Needed to process errors
  On Error GoTo Err_Label

  ' Runs the routine
  IntegrationObject.RunRoutineEx(sProjectName, sUnitName, sRoutineName, ParamArr)

  ' Waits until the test run is over
  While IntegrationObject.IsRunning
    DoEvents
  Wend

  ' Check the results
  If aqObject.GetVarType(IntegrationObject.RoutineResult) <> vbEmpty Then
    MsgBox "Script routine result : " + IntegrationObject.RoutineResult
  Else
    MsgBox "Script routine result did not return any result."
  End If

  Set LastResult = IntegrationObject.GetLastResultDescription
  Select Case LastResult.Status
    Case 0: MsgBox "The test run finished successfully."
    Case 1: MsgBox "Warning messages were posted to the test log."
    Case 2: MsgBox "Error messages were posted to the test log."
  End Select

Err_Label:
  ' Process errors
  If Err.Number > 0 Then
    MsgBox "Cannot start the test. Reason: " + Err.Description, vbCritical, "Error"
  End If

  ' Quits TestComplete
  TestCompleteApp.Quit
End Sub

Visual C# Early Binding

// Add the following lines to your unit
using System.Runtime.InteropServices;
using TestComplete;

...

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Invokes TestComplete upon a button click
            TestFunc();
        }

        private void TestFunc()
        {
            const string TCProgID = "TestComplete.TestCompleteApplication.10";
            object TestCompleteObject = null;

            // Initialize variables
            string sProjectFileName = "C:\\Work\\MyProject\\MyProjectSuite.pjs";
            string sProjectName = "TestProject";
            string sUnitName = "Unit1";
            string sRoutineName = "MyRoutine";

            string[] Params = { "John Smith", "[email protected]", "05/05/2009", "0000-1234-5678-9000" };

            // Obtains access to TestComplete
            try
            {
                TestCompleteObject = Marshal.GetActiveObject(TCProgID);
            }
            catch
            {
                try
                {
                    TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
                }
                catch
                {
                }
            }

            if (TestCompleteObject == null) return;


            // Obtain the ITestCompleteCOMManager object
            TestComplete.ITestCompleteCOMManager TestCompleteManager = (TestComplete.ITestCompleteCOMManager)TestCompleteObject;
            // Obtain the Integration object
            TestComplete.ItcIntegration IntegrationObject = TestCompleteManager.Integration;

            // We have a reference to the integration object.
            // Now we can use its methods and properties to automate TestComplete.

            // Loads the project suite
            IntegrationObject.OpenProjectSuiteEx(sProjectFileName);

        // Save data to a temporary file
        System.IO.StreamWriter MyFile = new System.IO.StreamWriter("C:\\TempFile.txt");
        MyFile.WriteLine("John Smith,[email protected],05/05/2009,0000-1234-5678-9000");
        MyFile.Close();

            try
            {
                // Runs the routine
                IntegrationObject.RunRoutineEx(sProjectName, sUnitName, sRoutineName, Params);

                // Waits until testing is over
                while (IntegrationObject.IsRunning())
                    Application.DoEvents();

                // Check the results
                object RoutineResult = IntegrationObject.RoutineResult;
                if (RoutineResult != null)
                    System.Windows.Forms.MessageBox.Show("Script routine returned " + RoutineResult.ToString());
                else
                    System.Windows.Forms.MessageBox.Show("Script routine did not return any result");


                
            switch (IntegrationObject.GetLastResultDescription().Status)
            {
                case TestComplete.TC_LOG_STATUS.lsOk:
                   System.Windows.Forms.MessageBox.Show(this, "The test run finished successfully.");
                   break;
                case TestComplete.TC_LOG_STATUS.lsWarning:
                    System.Windows.Forms.MessageBox.Show(this, "Warning messages were posted to the test log.");
                    break;
                case TestComplete.TC_LOG_STATUS.lsError:
                    System.Windows.Forms.MessageBox.Show(this, "Error messages were posted to the test log.");
                    break;
            }

            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message);
            }
            finally
            {
                // Closes TestComplete
                TestCompleteManager.Quit();
                // Releases COM objects
                Marshal.ReleaseComObject(IntegrationObject);
                Marshal.ReleaseComObject(TestCompleteManager);
                Marshal.ReleaseComObject(TestCompleteObject);
            }
        }
    }

Visual C# Late Binding

// Add the following lines to your unit
using System.Runtime.InteropServices;
using TestComplete;

...

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // Invokes TestComplete upon a button click
            TestFunc();
        }

        private void TestFunc()
        {
            const string TCProgID = "TestComplete.TestCompleteApplication.10";
            object TestCompleteObject = null;

            // Initialize variables
            string sProjectFileName = "C:\\Work\\MyProject\\MyProjectSuite.pjs";
            string sProjectName = "TestProject";
            string sUnitName = "Unit1";
            string sRoutineName = "MyRoutine";

            string[] Params = { "John Smith", "[email protected]", "05/05/2009", "0000-1234-5678-9000" };

            // Obtains access to TestComplete
            try
            {
                TestCompleteObject = Marshal.GetActiveObject(TCProgID);
            }
            catch
            {
                try
                {
                    TestCompleteObject = Activator.CreateInstance(Type.GetTypeFromProgID(TCProgID));
                }
                catch
                {
                }
            }

            if (TestCompleteObject == null) return;


            // Obtains Integration object during runtime
            dynamic IntegrationObject = TestCompleteObject.Integration;

            // We have a reference to the integration object.
            // Now we can use its methods and properties to automate TestComplete.

            // Loads the project suite
            IntegrationObject.OpenProjectSuiteEx(sProjectFileName);

        // Save data to a temporary file
        System.IO.StreamWriter MyFile = new System.IO.StreamWriter("C:\\TempFile.txt");
        MyFile.WriteLine("John Smith,[email protected],05/05/2009,0000-1234-5678-9000");
        MyFile.Close();

            try
            {
                // Runs the routine
                IntegrationObject.RunRoutineEx(sProjectName, sUnitName, sRoutineName, Params);

                // Waits until testing is over
                while (IntegrationObject.IsRunning())
                    Application.DoEvents();

                // Check the results
                object RoutineResult = IntegrationObject.RoutineResult;
                if (RoutineResult != null)
                    System.Windows.Forms.MessageBox.Show("Script routine returned " + RoutineResult.ToString());
                else
                    System.Windows.Forms.MessageBox.Show("Script routine did not return any result");


                if (IntegrationObject.GetLastResultDescription().Status == 0)
                {
                    System.Windows.Forms.MessageBox.Show(this, "The test run finished successfully.");
                }
                if (IntegrationObject.GetLastResultDescription().Status == 1)
                {
                    System.Windows.Forms.MessageBox.Show(this, "Warning messages were posted to the test log.");
                }
                if (IntegrationObject.GetLastResultDescription().Status == 2)
                {
                    System.Windows.Forms.MessageBox.Show(this, "Error messages were posted to the test log.");
                }

            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                System.Windows.Forms.MessageBox.Show("An exception occurred: " + ex.Message);
            }
            finally
            {
                // Closes TestComplete
                TestCompleteManager.Quit();
                // Releases COM objects
                Marshal.ReleaseComObject(IntegrationObject);
                Marshal.ReleaseComObject(TestCompleteObject);
            }
        }
    }

Here is sample script code where the execution is initiated via COM. The VB or C# code described above calls the MyRoutine procedure.

JavaScript, JScript

function MyRoutine(Param1, Param2, Param3, Param4)
{
  Log.Message("Param1: " + Param1);
  Log.Message("Param2: " + Param2);
  Log.Message("Param3: " + Param3);
  Log.Message("Param4: " + Param4);

  return Param1 + ", " + Param2 + ", " + Param3 + ", " + Param4
}

Python

def MyRoutine(Param1, Param2, Param3, Param4):
  Log.Message("Param1: " + Param1);
  Log.Message("Param2: " + Param2);
  Log.Message("Param3: " + Param3);
  Log.Message("Param4: " + Param4);

  return Param1 + ", " + Param2 + ", " + Param3 + ", " + Param4;

VBScript

Function MyRoutine(Param1, Param2, Param3, Param4)
  Log.Message "Param1: " & Param1
  Log.Message "Param2: " & Param2
  Log.Message "Param3: " & Param3
  Log.Message "Param4: " & Param4

  MyRoutine = Param1 & ", " & Param2 & ", " & Param3 & ", " & Param4
End Function

DelphiScript

function MyRoutine(Param1, Param2, Param3, Param4);
begin
  Log.Message('Param1: ' + Param1);
  Log.Message('Param2: ' + Param2);
  Log.Message('Param3: ' + Param3);
  Log.Message('Param4: ' + Param4);

  Result := Param1 + ', ' + Param2 + ', ' + Param3 + ', ' + Param4;
end;

C++Script, C#Script

function MyRoutine(Param1, Param2, Param3, Param4)
{
  Log["Message"]("Param1: " + Param1);
  Log["Message"]("Param2: " + Param2);
  Log["Message"]("Param3: " + Param3);
  Log["Message"]("Param4: " + Param4);

  return Param1 + ", " + Param2 + ", " + Param3 + ", " + Param4
}

See Also

Working With TestComplete via COM - Overview

Highlight search results