G
Guest
Using VB.NET in VS 2003.
This should be a simple routine, but it has me flummoxed.
I have to compare strings in two text files:
FILE1(srar) consists of lines of book titles.
FILE (srac) consists of multi-line “book recordsâ€, separated by blank rows.
The number of rows in each “book record†varies, as in this diagram:
1xxxxxx
xxxxxx
TitleRow
xxxxxx
2xxxxxx
TitleRow
xxxxxx
xxxxxx
xxxxxx
All I’m trying to do is to first read a title in File1, then read through
the entire File2 file, one “book record†at a time, looking for a matching
title. After other processing (not relevant here) and all book records have
been searched, go to the next File1 title and read all the book records in
File2 again. In short: typical looping within a loop.
The problem is that I cannot get it to work correctly! I know the issue
involves the blank rows and how the streamreader works. Here are core
excerpts of my code. Any enlightenment is greatly appreciated!
Dim RowCntr, ARBldr, ARCntr, MARCRowCntr, z, StartPos, TabPos As Long
Dim C1, C2, BkTitle, ArTitle, Arline, Acline, ArWtr, AcWtr, arbk As String
Dim srAR As System.IO.StreamReader = New StreamReader(FILE1.txt,
Encoding.GetEncoding(1252))
Dim srAC As System.IO.StreamReader = New StreamReader(FILE2.txt,
Encoding.GetEncoding(1252))
' Loop through the AR file (FILE1), reading each book title
For ARCntr = 0 To RdrArray.GetUpperBound(1)
MarcCntr = 1 ' initialize marc record counter variable
‘ Read through FILE2, one “book record†at a time.
Do
RowCntr = 1 ‘ reset variable for next book record row counter
' Now, the Inner loop supposed to read all lines for a single book
record.
Do
Acline = srAC.ReadLine
LibList.Add(Acline) ' new field row
If Acline=â€â€ Then ‘ found the blank row
LibList.Add(vbCr) ' new field row
RowCntr += 1 ' set value of RowCntr
End If
Loop Until srAC.Peek = -1
Loop Until srAC.Peek = -1 ' of first DO. Get another book record
Next ARCntr ' of the original FOR loop. Get another book title
I hope this is enough information to work with. I'll reply with more info if
necessary.
Thanks again for any help!
George
This should be a simple routine, but it has me flummoxed.
I have to compare strings in two text files:
FILE1(srar) consists of lines of book titles.
FILE (srac) consists of multi-line “book recordsâ€, separated by blank rows.
The number of rows in each “book record†varies, as in this diagram:
1xxxxxx
xxxxxx
TitleRow
xxxxxx
2xxxxxx
TitleRow
xxxxxx
xxxxxx
xxxxxx
All I’m trying to do is to first read a title in File1, then read through
the entire File2 file, one “book record†at a time, looking for a matching
title. After other processing (not relevant here) and all book records have
been searched, go to the next File1 title and read all the book records in
File2 again. In short: typical looping within a loop.
The problem is that I cannot get it to work correctly! I know the issue
involves the blank rows and how the streamreader works. Here are core
excerpts of my code. Any enlightenment is greatly appreciated!
Dim RowCntr, ARBldr, ARCntr, MARCRowCntr, z, StartPos, TabPos As Long
Dim C1, C2, BkTitle, ArTitle, Arline, Acline, ArWtr, AcWtr, arbk As String
Dim srAR As System.IO.StreamReader = New StreamReader(FILE1.txt,
Encoding.GetEncoding(1252))
Dim srAC As System.IO.StreamReader = New StreamReader(FILE2.txt,
Encoding.GetEncoding(1252))
' Loop through the AR file (FILE1), reading each book title
For ARCntr = 0 To RdrArray.GetUpperBound(1)
MarcCntr = 1 ' initialize marc record counter variable
‘ Read through FILE2, one “book record†at a time.
Do
RowCntr = 1 ‘ reset variable for next book record row counter
' Now, the Inner loop supposed to read all lines for a single book
record.
Do
Acline = srAC.ReadLine
LibList.Add(Acline) ' new field row
If Acline=â€â€ Then ‘ found the blank row
LibList.Add(vbCr) ' new field row
RowCntr += 1 ' set value of RowCntr
End If
Loop Until srAC.Peek = -1
Loop Until srAC.Peek = -1 ' of first DO. Get another book record
Next ARCntr ' of the original FOR loop. Get another book title
I hope this is enough information to work with. I'll reply with more info if
necessary.
Thanks again for any help!
George