String tables are resources (embedded configuration data) edited with the Workbench. A string table is a list of items identified by a name and referring to one or more character strings.
String tables are typically used for defining static texts to be used in the application. The following functions can be used for getting access to string tables in the programs:
StringTable: selects the active
LoadString: Load a string from the active table
In addition, each string table may contain several columns of texts for each item, and thus ease the localization of application, simply by defining a column for each language. This way the language can be selected dynamically at runtime, simply by specifying the active language (as a column) in the StringTable() function.
The name entered in the string table as an "ID" is automatically declared for the compiler and can directly be passed to the LoadString() function without re-declaring it. The name must conform to IEC standard naming rules.
Obviously, you could do the same by declaring an array of STRING variables and enter some initial values for all items in the array. By the way, string tables provide significant advantages compared to arrays:
- The editor provides a comfortable view of multiple columns at editing.
- String tables are loaded in the application code and does not require any further RAM memory unlike declared arrays.
- The string table editor automatically declares for you readable IDs for any string item to be used in programs instead of working with hard-coded index values.
If the text is too long for the STRING variable when used at runtime, it is truncated.
You can use special '$' sequences in strings in order to specify non printable characters, according to the IEC standard:
a single quote
a tab stop (ASCII code 9)
a carriage return character (ASCII code 13)
a line feed character (ASCII code 10)
carriage return plus line feed characters (ASCII codes 13 and 10)
a page break character (ASCII code 12)
any character (xx is the ASCII code expressed on two hexadecimal digits