Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

Application Server

QuickScript ​.NET variables

  • Last UpdatedJan 16, 2025
  • 3 minute read

Declare the QuickScript .NET variables before they can be used in QuickScript .NET scripts. Variables can be used on both the left and right side of statements and expressions.

Local variables or attributes can be used together in the same script. Variables declared within the script body lose their value after the script is executed. Those declared in the script body cannot be accessed by other scripts.

Variables declared in the Declarations area maintain their values throughout the lifetime of the object that the script is associated with.

Declare each variable in the script by a separate DIM statement followed by a semicolon. Enter DIM statements in the Declarations area of the Script tab page. The DIM statement syntax is as follows:

DIM <variable_name> [ ( <upper_bound>
[, <upper_bound >[, < upper_bound >]] ) ]
[ AS <data_type> ];

where:

DIM

Required keyword.

<variable_name>

Name that begins with a letter (A-Z or a-z) and whose remaining characters can be any combination of letters (A-Z or a-z), digits (0-9) and underscores (_). The variable name is limited to 255 Unicode characters.

<upper_bound>

Reference to the upper bound (a number between 1 and 2,147,483,647, inclusive) of an array dimension. Three dimensions are supported in a DIM statement, each being nested in the syntax structure. After the upper bound is specified, it is fixed after the declaration. A statement similar to Visual Basic’s ReDim is not supported.

The lower bound of each array dimension is always 1.

AS

Optional keyword for declaring the variable’s datatype.

<data_type>

Any one of the following 11 datatypes: Boolean, Discrete, Integer, ElapsedTime, Float, Real, Double, String, Message, Time or Object.

Data_type can also be a .Net data_type like System.Xml.XmlDocument or a type defined in an imported script library

If you omit the AS clause from the DIM statement, the variable, by default, is declared as an Integer datatype. For example:

DIM LocVar1;

is equivalent to:

DIM LocVar1 AS Integer;

In contrast to attribute names, variable names must not contain dots. Variable names and the data type identifiers are not case sensitive. If there is a naming conflict between a declared variable and another named entity in the script (for example, attribute name, alias or name of an object leveraged by the script), the variable name takes precedence over the other named entities. If the variable name is the same as an alias name, a warning message appears when the script is validated to indicate that the alias is ignored.

The syntax for specifying the entire array is "[ ]" for both local array variables and for attribute references. For example, to assign an attribute array to a local array, the syntax is:

locarr[] = tag.attr[];

DIM statements can be located anywhere in the script body, but they have to precede the first referencing script statement or expression. If a local variable is referenced before the DIM statement, script validation done when you save the object containing the script prompts you to define it.

The validation mentioned above occurs only when you save the object containing the script. This is not the script syntax validation done when you select the Validate Script button.

Don't cascade DIM statements. For example, the following examples are invalid:

DIM LocVar1 AS Integer, LocVar2 AS Real;

DIM LocVar3, LocVar4, LocVar5, AS Message;

To declare multiple variables, enter separate DIM statements for each variable.

When used on the right side of an equation, declared local variables always cause expressions on the left side to have Good quality. For example :

dim x as integer;

dim y as integer;

x = 5;

y = 5;

me.attr = 5;

me.attr = x;

me.attr = x+y;

In each case of me.attr, quality is Good.

When you use a variable in an expression to the right of the operator, its Quality is treated as Good for the purpose of data quality propagation.

You can use null to indicate that there is no object currently assigned to a variable. Using null has the same meaning as the keyword "null" in C# or "nothing" in Visual Basic. Assigning null to a variable makes the variable eligible for garbage collection. You may not use a variable whose value is null. If you do, the script terminates and an error message appears in the logger. You may, however, test a variable for null. For example:

IF myvar == null THEN ...

It is not possible to pass attributes as parameters for system objects. To work around this issue, use a local variable as an intermediary or explicitly convert the attribute to a string using an appropriate function call when calling the system object.

Related Links
TitleResults for “How to create a CRG?”Also Available in