Error reaching EOF before the end of the file.

ISUMiddy

New member
Joined
Feb 14, 2008
Messages
2
Programming Experience
Beginner
I am trying to read a text file, filled with ASCII characters. I am able to read about 1/5 of the file before my code stops, which I assume is because its reaching the end of file. I am using the inputstring function to read my data file. Should I use a different reading method or what would be best recommended for me?

I would use the streamreader, which does read the entire file, however it is unable to handle all of the ASCII characters correctly for example, a "ÿ" in the file is read by the streamreader as "�", thus changing the value I need.

Here is part of my code along with the data file I am trying to read.


VB.NET:
While Not EOF(1)
            oneChar = Strings.Asc(InputString(1, 1))
            If n = 1 Then
                F = (oneChar And 15)
                F2 = (oneChar)
            Else
                F = (oneChar)
                F2 = (oneChar And 15)
                n = 0
            End If
            If n = 1 Then
                lastCharF1 = F
                TotalF2 = (F2) + (lastCharF2 * 256)
                If TotalF2 > 2048 Then
                    TotalfrF2 = TotalF2 - 4096
                Else
                    TotalfrF2 = TotalF2
                End If
                F2Box = F2Box & TotalF2 & Chr(13) + Chr(10)
                F2FRBox = F2FRBox & TotalfrF2 & Chr(13) + Chr(10)
            Else
                TotalF1 = (lastCharF1 * 256) + (F)
                If TotalF1 > 2048 Then
                    TotalfrF1 = TotalF1 - 4096
                Else
                    TotalfrF1 = TotalF1
                End If
                F1Box = F1Box & TotalF1 & Chr(13) + Chr(10)
                F1FRBox = F1FRBox & TotalfrF1 & Chr(13) + Chr(10)
                lastCharF2 = F2
            End If
            n = n + 1
End While

Any help would be greatly appreciated. Thanks
 

Attachments

  • ACSIIfile.txt
    2.8 KB · Views: 19
Looks like its a know issu with EOF

http://www.thescripts.com/forum/thread14023.html

Personally I avoid all legacy VB functions. I'd find a way getting the streamreader to work. Maybe change the encoding type.

Dim sr As StreamReader = New StreamReader("TestFile.txt",System.Text.Encoding.GetEncoding("UTF-8"))

Find an encoding that works. I bet money there is one for the file you're working with.
 
New Issue with Binary Reader

I found a way that is reading my file correctly, however I came across a new problem that I dont know how to fix, the previous reply was quite useful, thanks.

My new problem deal with the Binaryreader. I am using a stream reader to read through the header information, then using the binary reader to analize the rest of the data. I have noticed that once I call the binary reader, there are around 100+ characters skipped before the Binary reader starts reading values. The code below deals with the portion reading the part of the file I included in the previous post. (br) indicates Binary Reader and (sr) indicates StreamReader. Thanks for looking at this for me.

VB.NET:
        StringCheck = Convert.ToChar(sr.Read)
        'insures Stringcheck is at least 10 characters long
        While l <= 10
            StringCheck = StringCheck + Convert.ToChar(sr.Read)
            l = l + 1
        End While

        While i = 1
            StringCheck = StringCheck & Convert.ToChar(sr.Read)
            If Microsoft.VisualBasic.Right(StringCheck, 12) = "|^Data Set^|" Then
                i = 2
                StringCheck = StringCheck & Convert.ToChar(sr.Read) & Convert.ToChar(sr.Read)
            End If
        End While
        x = x & StringCheck & Chr(13) + Chr(10) & Chr(13) + Chr(10) & Chr(13) + Chr(10)
        i = 1


        Iterations = (2 * 1 * 500) - 100

        While i < Iterations
            oneChar = (br.ReadByte())
            lastCharF1 = oneChar
            oneChar = (br.ReadByte())
            F = (oneChar And 15)
            TotalF1 = (lastCharF1) + (F * 256)

            x = x & lastCharF1 & "     ,     " & Chr(lastCharF1) & "     ,     " & F & "     ,     " & Chr(F) & "     ,     " & i & Chr(13) + Chr(10)
            i = i + 1
        End While
 
Back
Top