Syntax.CreateVarDef Method

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

Description

This method creates and returns a syntax element that corresponds to a variable declaration statement, for example:

JavaScript, JScript

var MyVariable;

VBScript

Dim MyVariable

DelphiScript

var MyVariable;

C++Script, C#Script

var MyVariable;

For Python users: This method returns the pass statement, because there is no variable declaration statement in Python.

Declaration

Syntax.CreateVarDef(Name)

Name [in]    Required    String    
Result A VarDefSyntax object

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

Name

Specifies the variable name to be defined. For example, MyVariable. This name must be a valid script identifier. Scripting languages supported by TestComplete have different naming rules, however there is an easy way to make the variable name suitable for all languages: use only letters (A..Z, a..z), digits (0..9) or underscores (_) in the name and start it with a letter.

Also, the variable name must not coincide with the names of TestComplete global scripting objects such as Sys, Log and others, as well as with the names of runtime objects provided by third-party plugins and script extensions.

Result Value

A VarDefSyntax object that corresponds to the variable declaration statement.

Example

The following example generates the declaration of a variable named MyVariable and displays this code in a message box:

JScript

function ShowVariableDeclaration()
{
  var oVarDef = Syntax.CreateVarDef("MyVariable");
  var strCode = Syntax.GenerateSource(oVarDef);
  aqDlg.ShowMessage(strCode)
}

VBScript

Sub ShowVariableDeclaration
  Dim oVarDef, strCode

  Set oVarDef = Syntax.CreateVarDef("MyVariable")
  strCode = Syntax.GenerateSource(oVarDef)
  aqDlg.ShowMessage strCode
End Sub

See Also

VarDefSyntax Object
CreateAssign Method
CreateCollection Method
CreateCondition Method
CreateInvoke Method
CreateIf Method
AddSyntaxToScript Method

Highlight search results