Input Past End of File in VB6

Bob Schneider
Bob Schneider used Ask the Experts™
on
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!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Analyst 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

Bob SchneiderCo-Owner

Author

Commented:
Perfect.  Thank you!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial