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. 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/>
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
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/>
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/>
"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/>
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/>
"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/>
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/>
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/>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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....
|
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...
|
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!
...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
| |