# Data Types

There are two types of variables.

- Basic Variables
  One variable that stores one value.
- User Data Type Variables
  One variable that can store multiple values (multiple variables handled as a single variable).

Note:

- For operation when the value (input value) stored in the variable is outside the input range (minimum/maximum value), refer to the following.
  Operation When Input Value is Outside the Input Range

## Basic Variables

The following is a list of the types of basic variables.

Data Type | Description
BOOL | This variable stores either 0 or 1.
SINT, USINT, INT, UINT, DINT, UDINT, LINT, ULINT, BYTE | These variables store integral values. Processing is faster compared to floating point type variables.
WORD, DWORD, LWORD | These variables store word type values.
STRING, WSTRING | These variables store text strings.
REAL, LREAL | These variables store floating point values. REAL variables can store larger values (such as calculations and constants) than integer type variables.
TIME, DATE, TIME_OF_DAY, DATE_AND_TIME | These variables store time and date values.

### SINT, USINT, INT, UINT, DINT, UDINT, LINT, ULINT, BYTE

Data Type | Signed | Data Length | Data Range
SINT | 2's complement | 8 bit | -128...127
USINT | - | 8 bit | 0...255
INT | 2's complement | 16 bit | -32768...32767
UINT | - | 16 bit | 0...65535
DINT | 2's complement | 32 bit | -2147483648...2147483647
UDINT | - | 32 bit | 0...4,294,967,295
LINT | 2's complement | 64 bit | -9,223,372,036,854,775,808...9,223,372,036,854,775,807
ULINT | - | 64 bit | 0...18,446,744,073,709,551,615
BYTE | - | 8 bit | 0...255

### WORD, DWORD, LWORD

Data Type | Data Length | Data Range
WORD | 16 bit | 0...65,535
DWORD | 32 bit | 0...4,294,967,295
LWORD | 64 bit | 0...18,446,744,073,709,551,615

### STRING, WSTRING

Data Type | Description
STRING | Stores up to 512 bytes of text. When using an external variable, string encoding is defined by the variable's [String Encode] property. Available string encode values are: UTF8, UTF16, ShiftJIS, Code Page850, GB2312, BIG5, KSC5601, CodePage1251, CodePage874, and CodePage1252. Note: You can also configure string encoding in equipment properties. The variable property setting takes priority over the equipment property. In the variable's [String Encode] property, select [Equipment Setting Type] to apply the equipment's string encode setting. The [String Encode] property is displayed only when the driver supports string encoding.
WSTRING | Stores up to 512 words of double-byte text. You can use the WSTRING data type with external variables only. String encoding is fixed as UTF16. You cannot change the [String Encode] setting in the variable properties, and the encoding in equipment properties is ignored.

Note:

- You can define the number of bytes or words the variable can store in the [Number of Bytes/Words] property.

- Recognizes the end of the text string with a NULL (0x00) or [Number of Bytes].

- For a selected variable or driver, if you use a text whose character code cannot be converted by the [String Encode], then the end of the string is recognized by character code.

- The relationship of high/low order for word data depends on [String Mode] in the selected driver.

### REAL, LREAL

Data Type | Data Length | Data Range
REAL | 32 bit | +/-3.402823E38 ... +/-1.1754944E-38
LREAL | 64 bit | +/-4.19E-307 ... +/-1.67E308

Note:

- The precision of REAL variables is limited to seven digits. If data precision is required (such as comparison operations), use integer variables.
  Examples
  Example 1: For the value 1.2345678, the resulting value is approximate as the eighth digit is dropped (after 1.234567).
  Example 2: The value 0.1 stored in a REAL variable could result in 0.1000000014901161.

- When using external REAL variables, make sure that the Double Word Order setting in the Device Configuration matches the setting in the equipment. If the settings do not match, the values of the external REAL variables will not be displayed properly.

- Use period (.) for decimal point of the variable value. The comma (,) is not supported for the decimal points.
  Even if comma (,) is used for decimal point of the variable value in the screen editing software or display unit, unexpected results, like that error is shown, the comma is ignored, or so on.

### TIME, DATE, TIME_OF_DAY, DATE_AND_TIME

Data Type | Description | Data Range
TIME | Stores the elapsed time in days and time. | - 24 d 20 h 31 m 23 s 648 ms ... 24 d 20 h 31 m 23 s 647 ms Note: When a negative value is set for [Initial value] and [Input range] properties in a TIME variable, the negative sign will display for each time unit. (Example: -24d -20:-31:-23.-648)
DATE | Stores the date. | When Using SP5000 Series Open Box (Windows 10 IoT Enterprise Model), IPC Series, or PC/AT 1970/01/01 ... 2106/02/07 Models other than those above 1970/01/01 ... 2038/01/19
TIME_OF_DAY | Stores the time. | 00:00:00 ... 23:59:59
DATE_AND_TIME | Combines the DATE and TIME_OF_DAY. | When Using SP5000 Series Open Box (Windows 10 IoT Enterprise Model), IPC Series, or PC/AT 1970/01/01 00:00:00 UTC ... 2106/02/07 06:28:15 UTC Models other than those above 1970/01/01 00:00:00 UTC ... 2038/01/19 03:14:07 UTC

Note:

- When using these variables, match the data types on the external device with the value of the stored data.
  If you have entered the value which is not in range of the external device address, then the entered value displays on the screen, but it is not set in the external device address.

- When you associate variables with different data types, sometimes the value of the source variable gets overwritten with a common result value.

  For example, convert a Real variable to an Integer variable: Set 123.4 to a REAL variable, then write the value to an INT variable and the result is 123. The value of the REAL variable is also updated to 123.

- When an integer value is input to the DATE_AND_TIME variable from an External Device, the stored value is offset by the time zone of the display unit. Therefore, for the integer value input, the date and time displayed by a Date/Time Display differ depending on the time zone.

SP5000 Series Open Box (Windows 10 IoT Enterprise Model), IPC Series, or PC/AT

Integer Value Input from External Device | UTC+0 (Range: 1970/01/01 00:00:00 ... 2106/02/07 06:28:15) | UTC+9 (Range: 1970/01/01 09:00:00 ... 2106/02/07 15:28:15)
0 | 1970/01/01 00:00:00 | 2106/02/07 06:28:16
1 | 1970/01/01 00:00:01 | 2106/02/07 06:28:17
: | : | :
32399 | 1970/01/01 08:59:59 | 2106/02/07 15:28:15
32400 | 1970/01/01 09:00:00 | 1970/01/01 09:00:00
: | : | :
4294967295 | 2106/02/07 06:28:15 | 2106/02/07 06:28:15

Models other than those above

Integer Value Input from External Device | UTC+0 (Range: 1970/01/01 00:00:00 ... 2038/01/19 03:14:07) | UTC+9 (Range: 1970/01/01 09:00:00 ... 2038/01/19 12:14:07)
0 | 1970/01/01 00:00:00 | 2038/01/19 03:14:08
1 | 1970/01/01 00:00:01 | 2038/01/19 03:14:09
: | : | :
32399 | 1970/01/01 08:59:59 | 2038/01/19 12:14:07
32400 | 1970/01/01 09:00:00 | 1970/01/01 09:00:00
: | : | :
2147483647 | 2038/01/19 03:14:07 | 2038/01/19 03:14:07

## User Data Type Variables

The following are the types of user data type variables.

- Array Variables
  Use a single variable to handle multiple variables of the same data type.
- Structure Variables
  Use a single variable to handle multiple variables of varying data types.

Note: Array holders and structure holders are also counted as variables.

### Array Variables

An array is a collection of variables with the same data type. Each variable in an array is called an element.

To understand how an array variable works, think of a variable as a box. As shown in the following diagram, the variable Number is a single box containing one value.

Think of an array as a row of boxes with a number associated with each box. In the following diagram, the array variable Number contains 5 elements 0-4. Variable values are stored in each of the 5 boxes.

To specify each variable in an array, specify the variable name followed by the element number enclosed in square brackets [ ].

(Example) Array with 5 elements

The element number usually starts with 0, but can also start with a positive or negative value.

(Example) Array starting with element number -1 with 5 elements

A multidimensional array is an array that contains other arrays. For example, an array that contains two DINT arrays is a two-dimensional array.

#### Number of Elements in Each Dimension and Dimension Settings

In the [Project Explorer] window, from [Variables] → [All User Data Types] → [Arrays], in the [Dimension] column, set both array dimension and number of elements.

For the steps in designing an array, refer to the following.

Steps to Design (Variables, Array, Structure)

For a 1-dimensional array, only specify the elements in the array.

(Example) For a 1-dimensional array with number of elements = 3, enter "3".

For a multidimensional array, in the [Dimension] field, specify the number of elements in each dimension, separated by a comma (,).

(Example) For a two-dimensional array where the first dimension has 3 elements (start number = 0) and the second dimension has 4 elements (start number = 0), enter "3,4".

This array definition is used to create the array variable Var1, shown below.

Note: To set the starting number of an element to something other than 0, instead of the number of elements, enter the starting and last element numbers separated by two periods (..) and the [Number of Elements] field calculates the total number of elements.

(Example) To set up a two-dimensional array where the first dimension has 3 elements starting from element 0, and the second dimension has 4 elements starting from element 3, enter "3,3..6".

After input, "3..6" is converted to 4 elements, and its array dimension starts from element number 3.

This array creates the array variable Var1, shown below.

#### Indirect Addressing of Array

Indirect addressing is the fastest way to access a variable value within a range of consecutive values in an array, to minimize memory consumption, and to update the value within milliseconds.

For indirect addressing of arrays, specify the array element number through a variable value or the property value of an object to specify the element of an array dynamically.

- To specify indirectly through a variable value:
  Enter "(Variable name).Value" in the brackets [] that specify the array element number.
  (Example) Var2[Var1.Value].Value: This is the value of array variable Var2 whose array element number is specified indirectly using the value of the variable Var1.
- To specify indirectly through the property value of an object:
  Enter "$GraphicalObject" followed by "(Object name).(Property name)" in the brackets [] that specify the array element number.
  (Example) Var2[$GraphicalObject.NumericDisplay1.CurrentValue].Value: This is the value of array variable Var2 whose array element number value is specified indirectly using the Current Value of a Numeric Display object, Numeric Display1.

Note:

When specifying an array element number indirectly with the property value of an object, enter "$GraphicalObject" before the object name.
Depending on the input assistance function, after typing "$" in the input or source property field, from the list of options you can select "$GraphicalObject" to enter the string easily.

The indirect addressing of an array supports the following:

- You can use in [Expression] converter.
  (Example: Array11[DINT1.value+2], Array21[Int2[Int3[Int1+1]]], Array31[Int1*4-(Int2+Int4/4)])

- A maximum 5 levels of nesting is supported for all variable data types.
  (Example: Array11[Array22[DINT1.value],DINT02.value])

### Structure Variables

A structure is a variable that holds a collection of other variables. Each variable in a structure is called an element. An element can be of any data type.

You can create a nested structure by adding another structure or an array as an element.

Think of a structure as a group of boxes with an element associated with each box.

In the following diagram, the structure variable DATA contains 3 elements. Variable values are stored in each of the 3 boxes.

## Operation When Input Value is Outside the Input Range

When the value to store in the variable is outside the range (minimum/maximum value), the value is treated as follows.

- When the value is exceeded on the external device
- When the value is exceeded with a Value Change operation [Loop]
- When the value is exceeded with a Value Change operation [Stop]
- When the value is exceeded with a Value Change [Set] operation, indirectly specified value, or Expression converter operation
- When the value is exceeded with a recipe

Note:

- For more information about Value Change operations, refer to Value Change.

### When the value is exceeded on the external device

Data Type | Description
STRING, WSTRING | Stores the characters that can fit.
Other than the above | The value of the portion that exceeds the input range is re-counted from the bottom of the input range and stored. Example) Unsigned 8 bit variable (value range: 0...255) Example 1: If you try storing 256, 0 is stored in the variable. (As the top limit is exceeded by 1, the bottom limit value of 0 is stored.) Example 2: If you try storing 257, 1 is stored in the variable. (As the top limit is exceeded by 2, the second value from the bottom limit 1 is stored.)

### When the value is exceeded with a Value Change operation [Loop]

The value of the portion that exceeds the input range is re-counted from the bottom of the input range and stored.

(Example): Unsigned 8 bit variable (value range: 0...255)

Example 1: If you try storing 256, 0 is stored in the variable. (As the top limit is exceeded by 1, the bottom limit value of 0 is stored.)

Example 2: If you try storing 257, 1 is stored in the variable. (As the top limit is exceeded by 2, the second value from the bottom limit 1 is stored.)

### When the value is exceeded with a Value Change operation [Stop]

Data Type | Description
STRING, WSTRING | Stores the characters that can fit.
Other than the above | The following are rounded to the top or bottom value. BOOL 1/0 SINT 127/-128 USINT, BYTE 255/0 INT 32767/-32768 UINT, WORD 65535/0 DINT 2147483647/-2147483648 UDINT, DWORD 4294967295/0 LINT 9223372036854775807/-9223372036854775808 ULINT, LWORD 18446744073709551615/0 REAL, LREAL Differs depending on the property setting. TIME 2147483647/-2147483648 DATE/TIME_OF_DAY, DATE_AND_TIME 4294967295/0

### When the value is exceeded with a Value Change [Set] operation, indirectly specified value, or Expression converter operation

Value is not stored.

### When the value is exceeded with a recipe

Data Type | Description
BOOL, REAL, LREAL | Value is not stored.
LINT, ULINT, LWORD | The following are rounded to the top or bottom value. LINT 9223372036854775807/-9223372036854775808 ULINT, LWORD 18446744073709551615/0
STRING, WSTRING | Stores the characters that can fit.
Other than the above | The value of the portion that exceeds the input range is re-counted from the bottom of the input range and stored. (Example): Unsigned 8 bit variable (value range: 0...255) Example 1: If you try storing 256, 0 is stored in the variable. (As the top limit is exceeded by 1, the bottom limit value of 0 is stored.) Example 2: If you try storing 257, 1 is stored in the variable. (As the top limit is exceeded by 2, the second value from the bottom limit 1 is stored.)