Home > Language Reference > Introduction to the Language > Constants and Variables

Constants and Variables


Constants
 

In programming, a constant is a value that never changes. The other type of values that automation scripts use is variables, symbols that can represent different values throughout the course of the script.

A constant can be:

The concatenation of strings of characters is made using the + operator, like "Hello"+" "+"WinTask x64"  for "Hello WinTask x64"

You are familiar with Constants in spreadsheets: you use Constants to place non-changing values in cells. 


Variables

The opposite of a Constant is a Variable. A Variable is a symbol or name that stands for a value. For example, in the expression
x+y
x and y are variables. 

For example you need to use a variable when you prompt the user for an answer in message box or dialog box. Further in the script, you can then perform a calculation on the data the user entered by referencing the variable.

Every variable has a name, called the variable name, and a data type. A variable's data type indicates what sort of value the variable represents. WinTask x64 supports four data types: integer, string, array, and unsigned. Note that floating-point data type is not supported, their string representation is used (see Add$ , Subtract$Multiply$  and Divide$  functions for floating-point numbers).

Variable names must contain only alphanumeric characters, must start with a letter and cannot contain spaces/accents. Variable names are not case-sensitive and the maximum length of a variable name is 32 characters.
If the variable receives integer values, the last letter of its name must not be a $ character:
count = 5
If the variable receives string values, the last letter of its name must be a $ character:
MyName$ = "John Smith"
When choosing a variable name, it is good practice to select a name that is descriptive of what the variable holds. For example, if a variable holds a name, then name it Name$ or MyName$. This makes the script more comprehensible. Also, be sure to avoid using WinTask x64 keywords, such as DATE.

An integer variable is initialized to 0 and can contain a maximum of 32-bit numbers (between -2 147 483 648 and +2 147 483 647). To initialize an integer variable to an other value than its default one, use the = operator:
a = 3
    b = 10
    c = a + b

A string variable is initialized to an empty string "". To initialize a string variable to an other value than its default one, use the = operator:
MyFirstName$ = "John"
    MyLastName$ = "Smith"
    MyName$ = MyFirstName$+" "+MyLastName$

 

See Using Arrays  article for array variables.


For Advanced Programmers, see
Global and Local Variables
Visibility of Variables


System Variables

System variables are predefined variables available in WinTask x64 language and can be used in any script. Their names always begin with the US pound symbol character (#). System variables are used to set the options for managing errors, defining timeouts, etc.

System variables have a predefined data type that cannot be changed. System variables have a default value and you can change most system variables simply by assigning a new value to the variable. For example, to change the current value of the #ActionTimeout system variable, which contains the timeout in seconds before returning an error, simply assign a new integer value:
#ActionTimeout = 60
This change will persist for the duration of the script execution or until you make a new assignment.


For Advanced Programmers: Unsigned data type

The UNSIGNED data type is for unsigned 32-bit integers used for specifying a memory address (API calls for example).
An UNSIGNED variable must be declared using the DIM statement at the beginning of the script (see Script Structure). For example:
Dim Addr as Unsigned

 

See also

Using Functions
Using Arrays
Expressions and Operators
Global and Local Variables
Visibility of Variables
Script Structure