variable size record length file parsing

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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



.



Relevant Pages

  • Re: auto gen no. based on fields
    ... I did not get a clear answer to whether the sequence number is over the ... Function GetNextNumberAs String ... Dim strSequenceNumber as String ... > each new quote, and yes ideally they would be as per your example. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Number sequence
    ... Function AdvanceSequence(S As String) As String ... Dim i As Integer ... and open any module on the Modules tab. ... generates a run number for fire calls in sequence. ...
    (microsoft.public.access.forms)
  • RE: File Sharing Lock COunt Exceeded Issue
    ... Dim ldbsCurrent As Database ... Dim strSQL As String, lstrCurrentCable As String ... Dim intNewWireSequence As Integer ... "ORDER BY CABLEID, WIRESEQUENCE, SEQUENCE;" ...
    (microsoft.public.access.modulesdaovba)
  • Re: How to generate Sequential String ?
    ... Private Function GenerateNextInSequence(ByVal current As String) As String ... 'This function procedure assumes a sequence of A001 through A999 ... Dim convertNumber As Integer ... 'set up the hex string from the input ...
    (microsoft.public.dotnet.academic)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)