473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Unable to read beyond the end of the stream

I have the code below:
Private Sub cmdFill_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdFill.Click
Dim Employee As UploadFile, Count As Integer, Temp As String
FileNum = FreeFile()
FileOpen(FileNum, TextBox1.Text, OpenMode.Random, , , Len(Employee))
Count = 1
lstView.Items.Clear()
Do While Not EOF(FileNum)
FileGet(FileNum, Employee, Count)
Temp = Str(Employee.UploadID) '+ " " + Employee.Name + " " +
Employee.Surname
lstView.Items.Add(Temp)
Count = Count + 1
Loop
FileClose(FileNum)
End Sub

Where "UploadFile" is a structure with 3 fields and "TextBox1.Text =
test.txt". Unfortunately at "FIleGet" I get the error message:
'System.IO.EndOfStreamException' Unable to read beyond the end of the stream.

Frustrated please help.
Nov 21 '05 #1
9 17877
"Zak Milas" <Za******@discussions.microsoft.com> schrieb:
I have the code below:
Private Sub cmdFill_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdFill.Click
Dim Employee As UploadFile, Count As Integer, Temp As String
FileNum = FreeFile()
FileOpen(FileNum, TextBox1.Text, OpenMode.Random, , ,
Len(Employee))
Count = 1
lstView.Items.Clear()
Do While Not EOF(FileNum)
FileGet(FileNum, Employee, Count)
Temp = Str(Employee.UploadID) '+ " " + Employee.Name + " " +
Employee.Surname
lstView.Items.Add(Temp)
Count = Count + 1
Loop
FileClose(FileNum)
End Sub

Where "UploadFile" is a structure with 3 fields and "TextBox1.Text =
test.txt". Unfortunately at "FIleGet" I get the error message:
'System.IO.EndOfStreamException' Unable to read beyond the end of the
stream.


Are you sure the file is long enough, which means, that the whole last
record can be read from the file?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Herfried,
Are you sure the file is long enough, which means, that the whole last
record can be read from the file?

Not offended however what do you mean by this?

Cor
Nov 21 '05 #3
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
Are you sure the file is long enough, which means, that the whole last
record can be read from the file?

Not offended however what do you mean by this?


Let's assume that the ASCII art below represents the file. Structure
instances are separated by "+" characters:

|----+----+----+--|

In the sample above, the last structure isn't saved completely, because for
some reason the file's length was reduced. So, when attempting to read the
last structure instance, an error would occur.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
Yes the content of the file for testing purposes is "1", that is the only
thing in the file. Of course once i get it work there is going to a lot more
info then just "1".

"Herfried K. Wagner [MVP]" wrote:
"Zak Milas" <Za******@discussions.microsoft.com> schrieb:
I have the code below:
Private Sub cmdFill_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdFill.Click
Dim Employee As UploadFile, Count As Integer, Temp As String
FileNum = FreeFile()
FileOpen(FileNum, TextBox1.Text, OpenMode.Random, , ,
Len(Employee))
Count = 1
lstView.Items.Clear()
Do While Not EOF(FileNum)
FileGet(FileNum, Employee, Count)
Temp = Str(Employee.UploadID) '+ " " + Employee.Name + " " +
Employee.Surname
lstView.Items.Add(Temp)
Count = Count + 1
Loop
FileClose(FileNum)
End Sub

Where "UploadFile" is a structure with 3 fields and "TextBox1.Text =
test.txt". Unfortunately at "FIleGet" I get the error message:
'System.IO.EndOfStreamException' Unable to read beyond the end of the
stream.


Are you sure the file is long enough, which means, that the whole last
record can be read from the file?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
"Zak Milas" <Za******@discussions.microsoft.com> schrieb:
Yes the content of the file for testing purposes is "1", that is the only
thing in the file. Of course once i get it work there is going to a lot
more
info then just "1".


Well, if the file only contains "1" and you are attempting to read a whole
structure instance with multiple members, this will fail.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
Below is my Structure, I have commented everything except the first one.
Structure UploadFile
Dim UploadID As Integer
'Dim SerialNumber As String
'Dim CurrentDate As Date
'Dim SupportStaff As String
'Dim ClientEmail As String
'Dim FileName As String
'Dim FileSize As Integer
'Dim EmailType As String
End Structure

therefore its reading only one member in the structure.

"Herfried K. Wagner [MVP]" wrote:
"Zak Milas" <Za******@discussions.microsoft.com> schrieb:
Yes the content of the file for testing purposes is "1", that is the only
thing in the file. Of course once i get it work there is going to a lot
more
info then just "1".


Well, if the file only contains "1" and you are attempting to read a whole
structure instance with multiple members, this will fail.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
"Zak Milas" <Za******@discussions.microsoft.com> schrieb:
Below is my Structure, I have commented everything except the first one.
Structure UploadFile
Dim UploadID As Integer
'Dim SerialNumber As String
'Dim CurrentDate As Date
'Dim SupportStaff As String
'Dim ClientEmail As String
'Dim FileName As String
'Dim FileSize As Integer
'Dim EmailType As String
End Structure

therefore its reading only one member in the structure.

Did you use 'FilePut' for a file that was opened in binary mode
('FileOpen(..., ..., OpenMode.Binary)') when writing the file?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8
Actually the file was not opened in binary mode. I opened it as Random. After
I had used the FilePut(FileNum, Employee, Count) command, what ever was in my
text file was removed.

"Herfried K. Wagner [MVP]" wrote:
"Zak Milas" <Za******@discussions.microsoft.com> schrieb:
Below is my Structure, I have commented everything except the first one.
Structure UploadFile
Dim UploadID As Integer
'Dim SerialNumber As String
'Dim CurrentDate As Date
'Dim SupportStaff As String
'Dim ClientEmail As String
'Dim FileName As String
'Dim FileSize As Integer
'Dim EmailType As String
End Structure

therefore its reading only one member in the structure.

Did you use 'FilePut' for a file that was opened in binary mode
('FileOpen(..., ..., OpenMode.Binary)') when writing the file?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9
Hello Thank you for your input. i found out what the problem was. It is the
content of the text file needed a space and a new line after the last entry.
Thank you once again.

"Zak Milas" wrote:
Actually the file was not opened in binary mode. I opened it as Random. After
I had used the FilePut(FileNum, Employee, Count) command, what ever was in my
text file was removed.

"Herfried K. Wagner [MVP]" wrote:
"Zak Milas" <Za******@discussions.microsoft.com> schrieb:
Below is my Structure, I have commented everything except the first one.
Structure UploadFile
Dim UploadID As Integer
'Dim SerialNumber As String
'Dim CurrentDate As Date
'Dim SupportStaff As String
'Dim ClientEmail As String
'Dim FileName As String
'Dim FileSize As Integer
'Dim EmailType As String
End Structure

therefore its reading only one member in the structure.

Did you use 'FilePut' for a file that was opened in binary mode
('FileOpen(..., ..., OpenMode.Binary)') when writing the file?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rafal 'Raf256' Maj | last post by:
Hi, I need to parse a file. This means reading from it as from std::istream. But - sometimes I also need to put-back some text I read before. What type of string can I use for that? Something...
2
by: Bob Rock | last post by:
I already found an alternative way to accomplish this (using ReadBytes), still I'd like to understand why I'm getting and error reading a text file using the following method. The exception is...
1
by: ywchan | last post by:
I have used a stream reader and sometimes it contains more than one rows of text. How to read all the lines in a stream reader? sr.Readline can only get line by line...and every times the total...
2
by: om | last post by:
hi I an new to c++ and was wondering if anyone could advise me how to read a stream coming from a http source thanks alot...
4
by: csharpula csharp | last post by:
Hello,I am trying to read from a zip stream and one of the files is of a 0 size (0 bytes)- Exception is thrown as a result but there are some other files after it in a stream which I want to keep...
6
by: =?Utf-8?B?RGFu?= | last post by:
I need to read an HTTP stream that is defined as excel format. How can I access this via ADO.Net? This dataset pastes nicely into excel....
2
by: Jack | last post by:
Hi, I want to read a string a chars from a stream, and put it into a string. At the moment, I'm creating a buffer of a fixed size, and reading the stream of text into it. It works, but I have...
11
by: csharpula csharp | last post by:
Hello, I would like to know how can I read a file by this way: Read from line X to Y and in other iteration from line Y to P and on and on. How to implement it? Which method and how? Thank u! ...
3
by: hdbbdh | last post by:
Hello everyone, I try to read a stream and save it as byte array to add it later to zip file. this is the code that I use Dim totalbytes As Byte() = Nothing Dim iBytesRead As Integer Dim...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.