Use assignments and type conversions

Completed

The assignments statement is the most frequently used statement in your application. With an assignment statement, you can set a value to a variable or the statement will assign a value to a variable.

To assign a value (or an expression) to a variable, use the := assignment operator. You can read this statement as becomes.

The assignment statement can also assign an expression to a variable. The expression 5 + 5 results in the integer value of 10, which will be assigned to the variable. You can also use other variables in the assignment. The following example shows the variables A and B being used, which will also result in the integer value of 10.

Example of using an Assignment operator.

When you are assigning a value (from another variable) to a variable, the data type of the value and the variable must be the same. You can't assign a text value to an integer variable or an integer to a text variable.

Some data types convert automatically, but only string and numeric data types allow automatic type conversion.

When you have two variables that have a string data type, such as text or code, you can assign the variable values to each other, and the system will automatically convert them to the other type.

Example of using the Convert text to code.

In the previous example, the value of the variable Description was assigned to the variable Code. Because the variable Code is of data type Code, it will automatically convert all lowercase letters to uppercase, and it will remove all leading and trailing spaces. In a Code data type, the value is always in uppercase letters and doesn't have leading or trailing spaces. The length of the two variables should be the same.

Numeric data types also include an automatic type conversion, but with some considerations. The value needs to be within the range of the variable. You can't assign a BigInteger value to an Integer data type if it exceeds the range of the integer.

If you try to convert a Decimal value to an Integer data type, it must be a whole number. When you are converting an Integer to a Char, the value must be between 0 and 255.