variable size record length file parsing
- From: "Matt Williamson" <ih8spam@xxxxxxxxxxx>
- Date: Mon, 14 May 2007 13:34:51 -0400
I need help parsing a file that will have variable sized record lengths.
I've done this in the past with a fixed size record, but I'm not sure what
the best approach would be with variable sized records.
This is my routine for doing it with a fixed length record with each record
being 752 chars.
Public Sub ParseFILE(sFileIn As String, sFileOut As String)
Dim uIMF As ImportFields
Dim s() As ImportFields
Dim lRsize As Long
Dim f As Long, r As Long
Dim sSQL As String, sSC As String
Dim sSign As String, sQuantity As String
f = FreeFile
Open sFileIn For Binary As f
DoEvents
' Determine record count
lRsize = Len(uIMF)
r = (LOF(f) - 752) \ lRsize
' Allocate array, read data
ReDim s(1 To r)
Get #f, 752, s
Close f
f = FreeFile
Open sFileOut For Output As f
For r = 1 To UBound(s)
If (r Mod 100) = 0 Then DoEvents
sSQL = r & "|" & Trim(s(r).SeqNum) & "|" & (s(r).Prefix) & "|" &
Trim$(s(r).Portcode) & "|"
Print #f, sSQL
Next
Close f
End Sub
The file has chars 4-11 of each line as a sequence number. I need to figure
out the best way to determine the length of each record that has the same
sequence number so I can change the 752 in the above sub to the new record
length.
The only way I can think of is opening the file as Input, using Line input
and check each line for the sequence number and adding the Len() of the
lines together. I'm sure there is a better way though. Plus, I don't think I
can open a file in binary mode and Input mode at the same time, so I'd have
to make a copy of the file first to do it that way which seems like overkill
to me.
Example:
GMA00000001
GMB00000001
GMA00000002
GMB00000002
GM100000002
GM200000002
GMA00000003
GMB00000003
GM100000003
GMA00000004
GMB00000004
GM100000004
GM200000004
GM800000004
GMA00000005
GMB00000005
GM100000005
GM200000005
TIA
Matt
.
- Follow-Ups:
- Re: variable size record length file parsing
- From: J French
- Re: variable size record length file parsing
- From: Mike Williams
- Re: variable size record length file parsing
- Prev by Date: spliting a string up
- Next by Date: Re: spliting a string up
- Previous by thread: spliting a string up
- Next by thread: Re: variable size record length file parsing
- Index(es):
Relevant Pages
|