CONVERT

ScriptEigener Objekttyp in der Automation Engine function: Converts the data type of a value.

Syntax 

CONVERT (Data type, value)

Syntax

Description/Format

Data type

Data type to which conversion is required.
Allowed values: "unsigned", "signed", "float" and "string"

unsigned: positive integers without signs
signed: integers with signs
float: floating point number
string: string, text

Data types are indicated without inverted commas.

Value

Value whose data type should be converted to a different data type.

Format: script literal or script variable

Numbers must also be specified in inverted commas.

Return code

Value including the converted data type.

Comments 

This script function can be used to convert the data type of a value that has been specified directly or via a script variable to a different data type. The return code is the converted value which must be assigned to a target variable.

Ensure that the data type of the value that should be converted complies with the target variable's data type when you use this script function.

Strings can only be converted to numbers if the string includes a number in a valid format.

Attempts to convert a higher number type to a lower one have the effect that decimal numbers are rounded or signs are removed.

Conversion is not possible if the target variable's data type does not comply with the function's parameter "Data type". The result is a scripting error.

Note that you cannot convert negative numbers with this script function

Example

The first example converts a positive integer into a string.

:define &unsigned#, unsigned
:define &string#, string

:set &unsigned# = 12
:set &string# = CONVERT(string, &unsigned#)

The second example converts a string to a number. This is only possible if the string consists of a number that has a valid format for the target data type.

:define &unsigned#, unsigned
:define &string#, string

:set &string# = "1234"
:set &unsigned# = CONVERT(unsigned,&string#)

See also: