Form functions takes the value of a variable and format it as a String. You can also write custom Form functions for structures. They can be invoked in expressions and are also used by Print, Trace, and Assert commands.
PRINT Variable '|' Format trace Variable '|' Format assert [Condition] {'error' | 'fault'} [Variable ['|' Format]] form( String, StringFormat ) form( Enumeration, StringFormat ) form( Enumeration, IntegerFormat ) form( Integer, IntegerFormat ) form( Real, RealFormat ) form( Structure, StructureFormat )
The first argument to a Form function is an expression whose result is to be formatted. The second argument is a String containing a template describing the format applied to the result. This Format Specification has a formal syntactic definition of the Format parameter.
The type or the first argument is a self typed expression. If untyped it is treated as a String expression. The second template argument is always a String expression. When formatting an enumeration declared as a list of symbolic names, its uppercased value it treated as a String. Enumerations declared as a range of integers are treated as an integer.
When a template character is repeated, it can be abbreviated by following the character with a decimal count of the number of repetitions. For example, "DDDD" can also be written as "D4". Repeat counts may not begin with zero and is limited to two characters.
Similarly you can place a pound sign after a template character to repeat repeat it zero or more times corresponding to the number of digits in the value being formatted. Essentially, it applies the preceeding form character to the remainder of digits in the expression parameter.
For example, "H#" is used to format an integer as a hexadecimal number with no leading zeros or blanks. Note that the pound sign can only follow format characters corresponding to the Expression value. For numeric expressions a pound may only follow a radix character, D, H, O or B. For Strings these are X, L, U and C.
Any character included in the template that is not one of the format control chacters described below will be copied to the result as a literal character. Any character can be included as a literal in the output by preceeding it with an equal sign. A count can also follow the literal to repeat it in the output. Including, "=*40" in a format template will insert 40 stars in the output.
For intrinsic Form funtions, the Format template is interpreted from left to right. Characters determine how a corresponding numeric digit or String character is formatted along with any literals to be included in the result.
Structures can be formatted by overloading the Form function. There is no intrinsic format for structures. Instead you can write a function with the following signature; where <Type> is replaced with the name of the structure. In this case the function determines how the Format parameter is interpreted.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: : function FORM..<Type>: A custom Form function for a structure: <Type> entry <Type>, &A variable to be formatted Format = "" string :An optional custom format exit Form string :The formatted result : :...............................................................................