Promotic

PmFormat object formatting string

Format of conversion between value and string.

Parameters of a text string are in the KeyVal format, which is filled from the value of of the sFormat parameter of the SetFormat or CreatePmFormat method.

Keys common to all types:

Type:xx; - Value type. For example "Type:Float;".
Float (default) - real number
Int - integer
Bool - logical value (1/0)
String - text string
DateTime - Date and time
TimeSpan - Time-span
Len:nn - Total number of characters excluding LTxt and RTxt
for numeric values including Sign, DSep, Group. For example "Len:6;".
See: Combination of keys Len, DLen, IfLong and Group.
-1 (default) - unlimited, for Scan find end of a number
n - defined number of characters
IfShort:nn - What to do if the value is shorter than Len. For example "Len:4;IfShort:2;".
0 (default) - do nothing
1 - add space character to the LEFT
2 - add space character to the RIGHT
7 - only for numeric values: add zeros from the left between the sign and the first digit (for non-numeric values like IfShort:1)
IfLong:nn - What to do if the value is longer than Len. For example "Len:4;IfLong:2;".
See: Combination of keys Len, DLen, IfLong and Group.
0 (default) - do nothing, it means keep long
1 - crop from LEFT to length Len
2 - crop from RIGHT to length Len
4 - fill with the character specified in IfLongPar to the length of Len
5 - replace with text defined in IfLongPar
7 - only for numeric values: scientific format max to IfLongPar (for non-numeric values like IfLong:2)
IfLongPar:ss - Specifies the character(s) to fill in for the IfLong parameter. For example "Len:4;IfLong:5;IfLongPar:MyErr;".
ss - Character(s)
for IfLong:4; - the character to fill with (default="", uses the asterisk "*" to fill)
for IfLong:5; - replacement text (default="")
LTxt:ss - Text to the left of the value For example "LTxt:Value ;".
See: Using Radix and other keys to format the value.
RTxt:ss - Text to the right of the value (for Scan there must not be RTxt inside the value). For example "RTxt:°C;".
See: Combination of keys RTxt and DLen for value of the Float type.
Case:nn - Conversion to upper/lower case characters (characters in LTxt and RTxt are not converted). For example "Case:2;".
See: Examples for String type and other keys to format the value.
0 (default) - keep unchanged
1 - UpperCase - upper case characters
2 - LowerCase - lower case characters

Keys common to all numbers:

Radix:nn - Other numeric system (for Int type). For example "Type:Int;Radix:16;".
See: Using Radix and other keys to format the value.
2 - binary
8 - octal
10 (default) - decimal
16 - hexadecimal, hex characters will be small but can be enlarged using Case:1;
Sign:nn - How to display the plus sign. For example "Sign:1;".
See: Using Sign to align plus and minus values.
0 (default) - do not display (display only "-")
1 - display "+" (if zero, then space)
2 - display " " (space)
Group:nn - Grouping groups of numbers into triples. For example "Group:1;".
See: Combination of keys Len, DLen, IfLong and Group.
0 (default) - no grouping
1 - group to the left of the decimal separator (thousands)
2 - group to the right of the decimal separator (thousandths)
3 - group to the left and to the right of the decimal separator (thousands and thousandths)
GroupSep:nn - Separator between groups For example "Group:1;GroupSep:2;".
0 (default) - space
1 - dot
2 - comma
DLen:nn - Number of characters to the right of the decimal separator. For example "DLen:3;".
See: Combination of keys Len, DLen, IfLong and Group.
-1 (default) - unlimited (filling up to the number specified in Len, but if Len=-1 then DLen:3)
n - integer including Group separator (3=default)
DSep:nn - Decimal dot type (relevant only if DLen!=0). For example "DSep:1;".
0 (default) - period "."
1 - comma ","
DZero:nn - Zeros to the right of the number (relevant only if DLen!=0). For example "DZero:1;".
0 (default) - keep the zeroes
1 - replace zeroes by spaces
2 - Optimize (delete zeros and eventually also the decimal separator)

Keys for DateTime:

Fmt:ss - Time format see: Formatting rule for time (DateTime). For example "Type:DateTime;Fmt:%Y.%m.%d %H:%M:%S.%T;".
See: Examples for DateTime type.

Keys for TimeSpan

Fmt:ss - Time-span format see: Formatting rule for time-span (TimeSpan). For example "Type:TimeSpan;Fmt:%*N%*d-%H:%M:%S.%T;".
See: Examples for TimeSpan type.

Other keys:

FmtC:ss - C language conversion format (obsolete way kept to maintain compatibility). Description see: C language formatting rule. For example "FmtC:%5.2f;".
See: Using C language formatting FmtC.


Combination of keys RTxt and DLen for value of the Float type:
JavaScriptVBScriptSelect and copy to clipboard

var oFmt = Pm.CreatePmFormat("Type:Float;RTxt: %;DLen:2;");
var Val = oFmt.Format(90.845);
// formatted value in the Val variable is: "90.84 %"
Combination of keys Len, DLen, IfLong and Group:
JavaScriptVBScriptSelect and copy to clipboard

var oFmt = Pm.CreatePmFormat("Len:12;DLen:7;IfLong:2;Group:3;");
var Val = oFmt.Format(-1234567.123456);
// formatted value in the Val variable is: "-1 234 567.1"
Using Sign to align plus and minus values:
JavaScriptVBScriptSelect and copy to clipboard

var oFmt = Pm.CreatePmFormat("Sign:2;");
var Val = oFmt.Format(1235.67);
// formatted value in the Val variable is: " 1235.670"
Val = oFmt.Format(-1235.67);
// formatted value in the Val variable is: "-1235.670"
Using Radix and other keys to format the value:
JavaScriptVBScriptSelect and copy to clipboard

// hexadecimal
var oFmt = Pm.CreatePmFormat("Type:Int;Radix:16;LTxt:0x;Case:1;");
var Val = oFmt.Format(10.58);
// formatted value in the Val variable is: "0xB"
var nVal = oFmt.Scan(Val);
// nVal = 11

oFmt = Pm.CreatePmFormat("Type:Int;Radix:8;LTxt:0o;");
Val = oFmt.Format(10.58);
// formatted value in the Val variable is: "0o13"
nVal = oFmt.Scan(Val);
// nVal = 11

oFmt = Pm.CreatePmFormat("Type:Int;Radix:2;LTxt:0b;");
Val = oFmt.Format(3.4);
// formatted value in the Val variable is: "0b11"
nVal = oFmt.Scan(Val);
// nVal = 3
Examples for Bool type and other keys to format the value:
JavaScriptVBScriptSelect and copy to clipboard

var oFmt = Pm.CreatePmFormat("Type:Bool;");
var Val = oFmt.Format(3.14);
// formatted value in the Val variable is: "1"
Val = oFmt.Format(0);
// formatted value in the Val variable is: "0"

oFmt = Pm.CreatePmFormat("Type:Bool;LTxt:Ln;RTxt:V;");
Val = oFmt.Format(true);
// formatted value in the Val variable is: "Ln1V"
Val = oFmt.Format(false);
// formatted value in the Val variable is: "Ln0V"
Examples for String type and other keys to format the value:
JavaScriptVBScriptSelect and copy to clipboard

var oFmt = Pm.CreatePmFormat("Type:String;LTxt:x;RTxt:q;Case:1;");
var Val = oFmt.Format("aBcD");
// formatted value in the Val variable is: "xABCDq"

oFmt = Pm.CreatePmFormat("Type:String;LTxt:X_;RTxt:_Q;Len:6;IfLong:2;");
Val = oFmt.Format("abcdefgh");
// formatted value in the Val variable is: "X_abcdef_Q"
Examples for DateTime type:
JavaScriptVBScriptSelect and copy to clipboard

var t = Pm.CreateDate(2022, 2, 13, 4, 15, 6, 789);

var oFmt = Pm.CreatePmFormat("Type:DateTime;Fmt:%2d.%2m.%4Y %2H:%2M:%2S.%T");
var Val = oFmt.Format(t);
// formatted value in the Val variable is: "13.02.2022 04:15:06.789"

oFmt = Pm.CreatePmFormat("Type:DateTime;Fmt:%2d.%2m.%4Y %2H:%2M:%2S");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "13.02.2022 04:15:06"

oFmt = Pm.CreatePmFormat("Type:DateTime;Fmt:%4Y.%2d.%2m %2H:%2M:%2S");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "2022.13.02 04:15:06"

oFmt = Pm.CreatePmFormat("Type:DateTime;Fmt:%*d.%*m.%*Y %*H:%*M:%*S.%T");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "13.2.2022 4:15:6.789"

oFmt = Pm.CreatePmFormat("Type:DateTime;Fmt:%*Y.%*m.%*d");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "2022.13.2"

oFmt = Pm.CreatePmFormat("Type:DateTime;Fmt:%*H:%*M:%*S");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "4:15:6"

oFmt = Pm.CreatePmFormat("Type:DateTime;Fmt:%Y%m%d%H%M%S");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "20221302041506"
Examples for TimeSpan type:
JavaScriptVBScriptSelect and copy to clipboard

var t = Pm.CreateDate(0, 0, 53, 4, 15, 6, 789);

var oFmt = Pm.CreatePmFormat("Type:TimeSpan;Fmt:%2d %2H:%2M:%2S.%T");
var Val = oFmt.Format(t);
// formatted value in the Val variable is: "53 04:15:06.789"

oFmt = Pm.CreatePmFormat("Type:TimeSpan;Fmt:%*d %*H:%*M:%*S");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "53 4:15:6"

oFmt = Pm.CreatePmFormat("Type:TimeSpan;Fmt:%d%m%Y%H%M%S%T");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "13022022041506789"

oFmt = Pm.CreatePmFormat("Type:TimeSpan;Fmt:%N%2d %2H:%2M:%2S.%T");
Val = oFmt.Format(-t);
// formatted value in the Val variable is: "-53 04:15:06.789"

t = Pm.CreateDate(0, 0, 1053, 4, 15, 6, 789);
oFmt = Pm.CreatePmFormat("Type:TimeSpan;Fmt:%*N%d-%H:%M:%S.%T");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "1053-04:15:06.789"

oFmt = Pm.CreatePmFormat("Type:TimeSpan;Fmt:%*N%H:%M:%S.%T");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "25276:15:06.789"

oFmt = Pm.CreatePmFormat("Type:TimeSpan;Fmt:%*N%M:%S.%T");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "1516575:06.789"

oFmt = Pm.CreatePmFormat("Type:TimeSpan;Fmt:%*N%S.%T");
Val = oFmt.Format(t);
// formatted value in the Val variable is: "90994506.789"
Using C language formatting FmtC:
JavaScriptVBScriptSelect and copy to clipboard

var oFmt = Pm.CreatePmFormat("FmtC:%d"");
var Val = oFmt.Format(1);
// formatted value in the Val variable is: "1"

oFmt = Pm.CreatePmFormat("FmtC:x%dq");
Val = oFmt.Format(1);
// formatted value in the Val variable is: "x1q"

oFmt = Pm.CreatePmFormat("FmtC:%f");
Val = oFmt.Format(12.3456789);
// formatted value in the Val variable is: "12.3456789"

oFmt = Pm.CreatePmFormat("FmtC:%13.2f");
Val = oFmt.Format(123456789.123456789);
// formatted value in the Val variable is: " 123456789.12"

oFmt = Pm.CreatePmFormat("FmtC:%x");
Val = oFmt.Format(255);
// formatted value in the Val variable is: "ff"

oFmt = Pm.CreatePmFormat("FmtC:%03X");
Val = oFmt.Format(10.58);
// formatted value in the Val variable is: "00B"

oFmt = Pm.CreatePmFormat("FmtC:n=%03X");
Val = oFmt.Format(10.58);
// formatted value in the Val variable is: "n=00B"
PROMOTIC 9.0.24 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r. o.