FormattedText
This is a Class for use in parsing data fields from fixed-format records based on one or more simple "Fortran like" format strings.
You assign the LCID to be used for conversion, defaulting to the current user's locale settings. Then assign one or more RecordFormat(n) properties to formatting strings.
Then read your raw records from a file line by line as text and call the ParseRecord() method, passing the String, a Variant array to receive the parsed values, and the format index for the format to be applied to the record.
RecordFormat Strings
These consist of a comma-separated list of optional "repeat counts", "type" characters, and field lengths in characters. Missing or non-numeric repeat count or length values are treated as 1.
Types and Pseudotypes:
The Boolean type requires a field length at least as long as the localized words used for True and False (i.e. 5 for English). If you need to handle a field using T and F for example, make it a String field and test it yourself after parsing each record.
Examples:
The RecordFormat property expects an index value from 0 to n, allowing you to set up multiple formats before you being parsing records.
Demos
The attached archive contains FormattedText.cls along with two demo Projects FmtText1 and FmtTest2 along with sample data.
FmtTest1 scans its way through a file of mixed record types and locates and extracts column headings and data values, putting the data into a 2-dimensional array with lower bounds of 1 instead of 0. Then this information is dumped to a flexgrid for viewing.
FmtTest2 reads a much simpler file containing several kinds of fields. It is also a German file where values are localized using German OLE conventions for data conversion from text.
In both cases the dumped data is displayed using current locale settings.
This is a Class for use in parsing data fields from fixed-format records based on one or more simple "Fortran like" format strings.
You assign the LCID to be used for conversion, defaulting to the current user's locale settings. Then assign one or more RecordFormat(n) properties to formatting strings.
Then read your raw records from a file line by line as text and call the ParseRecord() method, passing the String, a Variant array to receive the parsed values, and the format index for the format to be applied to the record.
RecordFormat Strings
These consist of a comma-separated list of optional "repeat counts", "type" characters, and field lengths in characters. Missing or non-numeric repeat count or length values are treated as 1.
Types and Pseudotypes:
X - "filler" (skipped, not returned as a field value)
S - String
T - String (trimmed)
I - Integer
L - Long
R - "real" (Single)
D - Double
B - Boolean
H - Hex (Long)
C - "chron" (Date) for date and time values
S - String
T - String (trimmed)
I - Integer
L - Long
R - "real" (Single)
D - Double
B - Boolean
H - Hex (Long)
C - "chron" (Date) for date and time values
The Boolean type requires a field length at least as long as the localized words used for True and False (i.e. 5 for English). If you need to handle a field using T and F for example, make it a String field and test it yourself after parsing each record.
Examples:
"X3,S10,T10,C10,C19,R13,B6,H8"
"7T11"
"R10, 17R13"
"7T11"
"R10, 17R13"
The RecordFormat property expects an index value from 0 to n, allowing you to set up multiple formats before you being parsing records.
Demos
The attached archive contains FormattedText.cls along with two demo Projects FmtText1 and FmtTest2 along with sample data.
FmtTest1 scans its way through a file of mixed record types and locates and extracts column headings and data values, putting the data into a 2-dimensional array with lower bounds of 1 instead of 0. Then this information is dumped to a flexgrid for viewing.
FmtTest2 reads a much simpler file containing several kinds of fields. It is also a German file where values are localized using German OLE conventions for data conversion from text.
In both cases the dumped data is displayed using current locale settings.