02-22-2005, 12:29 AM
An old trick I used with QBasic/VB to handle fixed width records in an ASCII text file was to define the "fields" in the records as a UDT and use random file acess to quickly read sections of the text file without having to input each line and mid$() what I needed.
The following code is a simple test for what I am trying to do. It has been adjusted to make the reading of the record sizes correct (4 byte AS STRING for an actual 5 character field).
The file being processed is as follows:
The ouput for the example shows:
So it is not limiting the AS STRING * to the size defined.
The following code is a simple test for what I am trying to do. It has been adjusted to make the reading of the record sizes correct (4 byte AS STRING for an actual 5 character field).
Code:
TYPE myrec field = 1
first AS STRING * 4
second AS STRING * 4
third AS STRING * 4
fourth AS STRING * 4
crlf as byte
END TYPE
DIM filerec AS myrec
DIM reccount AS LONG
OPEN "test1.txt" FOR RANDOM AS #1 LEN = LEN(filerec)
reccount = LOF(1) / LEN(filerec)
PRINT reccount
PRINT LEN(filerec)
get #1, 1, filerec
print filerec.first
print filerec.second
CLOSE #1
SLEEP
The file being processed is as follows:
Code:
11111ABCDE>>>>><<<<<
22222ABCDE>>>>><<<<<
33333ABCDE>>>>><<<<<
44444ABCDE>>>>><<<<<
55555ABCDE>>>>><<<<<
The ouput for the example shows:
Code:
5
21
11111ABCDE>>>>><<<<<
ABCDE>>>>><<<<<
So it is not limiting the AS STRING * to the size defined.