Knowing User's Scripting Language

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

When creating a custom action that generates script code, you may need to know which language is used in the user’s current project. For this, use the Syntax.CurrentLanguage property. It returns a string holding the language name -- JavaScript, JScript, Python, VBScript, DelphiScript, C#Script or C++Script.

In most cases, you would use the Syntax.CurrentLanguage property when you need to generate custom code for which there are no appropriate syntax objects. For example, a for or while loop. In this case, you can pre-define the desired code snippets for all scripting languages as plain text, and then choose the snippet that corresponds to the user’s current language. Note, however, that this approach requires that you are familiar with the syntax of the scripting languages supported by TestComplete.

The following example demonstrates how you can use the Syntax.CurrentLanguage property in the code of custom actions. It generates the Log.Message method call that was hard-coded as plain text in the action’s code:

JScript

function ShowLogMessageCall()
{
  var str;

  switch (Syntax.CurrentLanguage)
  {
    case "JavaScript" : case "JScript" : case "Python" : str = "Log.Message(\"Hello, world!\");"; break;
    case "VBScript" : str = "Log.Message \"Hello, world!\""; break;
    case "DelphiScript" : str = "Log.Message('Hello, world!');"; break;
    case "C#Script" : case "C++Script" : str = "Log[\"Message\"](\"Hello, world!\");"; break;
  }

  aqDlg.ShowMessage(str);
}

VBScript

Sub ShowLogMessageCall
  Dim str

  Select Case Syntax.CurrentLanguage
    Case "JavaScript", "JScript", "Python" str = "Log.Message(""Hello, world!"");"
    Case "VBScript"                        str = "Log.Message ""Hello, world!"""
    Case "DelphiScript"                    str = "Log.Message('Hello, world!');"
    Case "C#Script", "C++Script"           str = "Log[""Message""](""Hello, world!"");"
  End Select

  aqDlg.ShowMessage str
End Sub

See Also

Generating Script Code
CurrentLanguage Property

Highlight search results