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

AVEVA™ Plant SCADA

Converting and Formatting Cicode Variables

  • Last UpdatedJul 18, 2023
  • 5 minute read

Plant SCADA provides the following functions for converting variables.

  • IntToStr: converts an integer variable into a string

  • IntToReal: converts an integer into a floating-point variable

  • RealToStr: converts a floating-point variable into a string

  • StrToInt: converts a string into an integer variable

  • StrToReal: converts a string into a floating-point variable

You can convert data types without using these Cicode functions, but the result of the format conversion might not be what you expect. If you want more control over the conversion process, use the appropriate Cicode functions.

Note: Variables of type object cannot be converted to any other type.

When variables are automatically converted, or when the return value from a function call is converted, specific rules apply.

Converting Variable Integers to Strings

To convert an integer variable to a string:

IntVar=5;
StringVar=IntVar;

The value of StringVar is set to "5".

The format of the string is specified when the variable is defined in the database. However you can override this default format with the string format (:) operator, and use the # format specifier to set a new format. For example:

IntVar=5;
StringVar=IntVar:####

The value of StringVar = " 5". (The '#' formatting characters determine the size and number of decimal places contained in the string, that is a length of 4 with no decimal places.)

Converting Variable Integers to Real Numbers

When calling statements such as comparison or arithmetic operations that involve a mixture of variables of REAL and INT data types, there is no need to explicitly convert the variable of INT data type to REAL data type using the IntToReal function. Plant SCADA will automatically convert variables of INT data type to REAL data type before the operation is carried out.

However, if the expression only consists of variables of INT data type, the result of the expression will remain as INT data type and be subjected to its limitations such as integer overflow and wraparound. This does not change even if the expression is to be assigned to a variable of REAL data type.

If you want to increase the range of the expression, you will need to convert at least one of its operands to REAL data type using the IntToReal function.

Example

INT nVar1 = 1000000001;
INT nVar2 = 2000000002;
REAL rVar1 = 1.000001;
REAL rVar2 = 0.0;


// rVar2 = 1000000002.000001, IntToReal is not needed when operands are mixture of INT and REAL data types
rVar2 = nVar1 + rVar1;

// rVar2 = -1294967293.0, result is wrapped around due to range overflow of integer data type
rVar2 = nVar1 + nVar2;

// rVar2 = 3000000003.0, result is prompted to REAL data type when one of the INT operands is converted
rVar2 = nVar1 + IntToReal(nVar2);

Converting Real Numbers to Strings

To convert a real number variable to a string:

RealVar=5.2;
StringVar=RealVar;

The value of StringVar is set to "5.2".

Note: Unpredictable results may occur if you use large numbers with a large number of decimal places.

The format of the string is specified when the variable is defined in the database. However you can override this default format with the string format (:) operator, and use the # format specifier to set a new format. For example:

StrTag1=RealTag1:######.###

The value of StringVar = " 5.200". (The '#' formatting characters determine the size and number of decimal places contained in the string, that is a length of 10 including a decimal point and three decimal places.)

Converting Strings to Integers

To convert a string variable to an integer:

StringVar="50.25";
IntVar=StringVar;

The value of IntVar is set to 50. If StringVar contains any characters other than numeric characters, IntVar is set to 0.

Converting Strings to Real Numbers

To convert a string variable to a real number:

StringVar="50.25";
RealVar=StringVar;

The value of RealVar is set to 50.25. If StringVar contains any characters other than numeric characters, RealVar is set to 0.

Formatting Text Strings

A string in Cicode is represented as text positioned between double quote ( " ) delimiters. For example:

"This is my text string."

A string value can be assigned to a string variable. For example:

STRING sMyStringVariable;
sMyStringVariable = "This is my text string.";

More than one string can be joined together (concatenated) using the Cicode 'plus' mathematical operator ( + ). For example:

STRING sMyStringVariable;
sMyStringVariable = "This is my text string." + "This is my second
text string.";

The two strings would be joined together and assigned to the string variable sMyStringVariable. However, if subsequently displayed somehow, like in the following MESSAGE example, the concatenated string would look wrong because there is no space character positioned between the string sentences.

STRING sMyStringVariable;
sMyStringVariable = "This is my text string." + "This is my second
text string.";
MESSAGE("String Concatenation Example",sMyStringVariable,32);

To overcome this potential formatting problem, you could include an extra space as the last character in the strings, or include the space as a third string in the concatenation. For example:

sMyStringVariable = "This is my text string. " + "This is my
second text string. ";

or

sMyStringVariable = "This is my text string." + " " + "This is my
second text string. ";

However, these are considered poor programming practices and not recommended. Instead, you can use special string formatting commands known as escape sequences.

If the two strings (as used in the previous example), were formatted using appropriate escape sequences positioned within the strings, and subsequently displayed somehow, like in the following MESSAGE example, the concatenated string would look different, For example:

STRING sMyStringVariable;
STRING sNewLine = "^n";
sMyStringVariable = "This is my text string." + sNewLine + "This
is my second text string.";
MESSAGE("String Concatenation Example",sMyStringVariable,32);

Strings and string variables can also be concatenated as in the previous example. Be aware of how the newline escape sequence ( ^n ) was assigned to the string variable sNewLine, and how this value was concatenated between the other strings and assigned to the string variable sMyStringVariable for display in the MESSAGE function.

Escape Sequences (String Formatting Commands)

Cicode supports several escape sequences that you can use in text strings for custom formatting of the string. By using the appropriate Cicode escape sequences listed below you can format the string display to do such things as divide onto separate lines at specific positions, insert tab spaces, insert quotes, or to display Hexadecimal numbers.

Cicode escape sequences are preceded by a caret ( ^ ) character. The caret character is interpreted as a special instruction, and together with the characters immediately following it, are treated as an Cicode escape sequence formatting command. The escape sequences used in Cicode are:

^b

backspace

^f

form feed

^n

new line

^t

horizontal tab

^v

vertical tab

^'

single quote

^"

double quote

^^

caret

^r

carriage return

^0xhh

where hh is a hexadecimal number (for example, ^0x1A)

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