Input Past End of File in VB6

I am getting an "Input past end of file" with the code below...
            Set fsoIn = New Scripting.FileSystemObject
            Set fsoOut = New Scripting.FileSystemObject
            
            Set tsTxtFileIn = fsoIn.OpenTextFile(sPath & "rfid\putty.log", ForReading, False, TristateMixed)
            If fsoOut.FileExists(sPath & "rfid\" & iBox & ".txt") Then
                Set tsTxtFileOut = fsoOut.OpenTextFile(sPath & "rfid\" & iBox & ".txt", ForWriting, False, TristateMixed)
            Else
               Set tsTxtFileOut = fsoOut.CreateTextFile(sPath & "rfid\" & iBox & ".txt")
            End If
            
            With tsTxtFileIn
                Do Until .AtEndOfStream
                    If Left$(.ReadLine, 2) = "aa" Then
                        If Right$(.ReadLine, 2) <> "FS" Then
                        
Debug.Print Right$(.ReadLine, 2)

                            strIn = .ReadLine
                            strHex1 = CInt("&H" & Mid$(strIn, 33, 4))
                            strHex2 = CLng("&H" & Mid$(strIn, 9, 8))
                            If Not Left$(strHex2, 1) = "-" Then
                                strOut = Mid$(strIn, 4, 1) & "," & strHex2 & ",0," & _
                                         QUOTE & Mid$(strIn, 27, 2) & ":" & Mid$(strIn, 29, 2) & ":" & Mid$(strIn, 31, 2) & _
                                         "." & strHex1 & QUOTE & "," & Mid$(strIn, 4, 1) & ",0"
                                tsTxtFileOut.WriteLine strOut
                            End If
                        End If
                    End If
                Loop
                .Close
            End With
        End If

Open in new window


And it is including rows in the file that end in "FS", which I am trying to avoid.  Here is what I get when I run this:
BS
BS
BS
BS
BS
BS
FS
FS
FS
BS
BS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS
LS

Any help would be much appreciated!
Bob SchneiderCo-OwnerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Bob

As the code stands every time you have something like this you are reading a line from the input file,
If Left$(.ReadLine, 2) = "aa" Then

Open in new window

so by the time you reach here you've already read 2 lines from the input file.
strIn = .ReadLine

Open in new window


You should read the line from the text file into a variable and then use that variable in the rest of the code, something like this.
            Set fsoIn = New Scripting.FileSystemObject
            Set fsoOut = New Scripting.FileSystemObject
            
            Set tsTxtFileIn = fsoIn.OpenTextFile(sPath & "rfid\putty.log", ForReading, False, TristateMixed)
            If fsoOut.FileExists(sPath & "rfid\" & iBox & ".txt") Then
                Set tsTxtFileOut = fsoOut.OpenTextFile(sPath & "rfid\" & iBox & ".txt", ForWriting, False, TristateMixed)
            Else
               Set tsTxtFileOut = fsoOut.CreateTextFile(sPath & "rfid\" & iBox & ".txt")
            End If
            
            With tsTxtFileIn
                Do Until .AtEndOfStream
                    strIn = .ReadLine
                    If Left$(strIn, 2) = "aa" Then
                        If Right$(strIn, 2) <> "FS" Then
                        
                            Debug.Print Right$(strIn, 2)

                            strHex1 = CInt("&H" & Mid$(strIn, 33, 4))
                            strHex2 = CLng("&H" & Mid$(strIn, 9, 8))
                            If Not Left$(strHex2, 1) = "-" Then
                                strOut = Mid$(strIn, 4, 1) & "," & strHex2 & ",0," & _
                                         QUOTE & Mid$(strIn, 27, 2) & ":" & Mid$(strIn, 29, 2) & ":" & Mid$(strIn, 31, 2) & _
                                         "." & strHex1 & QUOTE & "," & Mid$(strIn, 4, 1) & ",0"
                                tsTxtFileOut.WriteLine strOut
                            End If
                        End If
                    End If
                Loop
                .Close
            End With
        End If

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob SchneiderCo-OwnerAuthor Commented:
Perfect.  Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.