Hi, I'm having some trouble with a StreamReader.
I use a System.IO.Strea mReader to read a text file and then print it.
If the user has selected a range of pages starting past the first page,
I have to make the StreamReader jump to some point in the file.
To make the StreamReader jump to where it should be, I use the
following code:
fReader.BaseStr eam.Seek(fileBo okmark + (Me.reportTextW idth *
linesPerPage * startPage), IO.SeekOrigin.B egin)
I've run this through the debugger, and the expression "fileBookma rk +
(Me.reportTextW idth * linesPerPage * startPage)" seems to be
calculating the starting character correctly.
When I start reading the file, I use:
line = fReader.ReadLin e()
....and this is where the problems occur!! I set a watch in the
debugger on fReader.BaseStr eam.Position. After the first operation (the
seek, shown above), fReader.BaseStr eam.Position is 2479. After the
ReadLine executes, fReader.BaseStr eam.Position is 3503, it has
increased by 1,024 Bytes! For all subsequent ReadLines,
fReader.BaseStr eam.Position does not change at all. Maybe I'm just not
quite understanding how the VB.NET StreamReader works... Does anyone
have an idea why this would be happening? Or maybe a better way to do
what I'm trying to do:
Jump to a position in a text file and read!
I use a System.IO.Strea mReader to read a text file and then print it.
If the user has selected a range of pages starting past the first page,
I have to make the StreamReader jump to some point in the file.
To make the StreamReader jump to where it should be, I use the
following code:
fReader.BaseStr eam.Seek(fileBo okmark + (Me.reportTextW idth *
linesPerPage * startPage), IO.SeekOrigin.B egin)
I've run this through the debugger, and the expression "fileBookma rk +
(Me.reportTextW idth * linesPerPage * startPage)" seems to be
calculating the starting character correctly.
When I start reading the file, I use:
line = fReader.ReadLin e()
....and this is where the problems occur!! I set a watch in the
debugger on fReader.BaseStr eam.Position. After the first operation (the
seek, shown above), fReader.BaseStr eam.Position is 2479. After the
ReadLine executes, fReader.BaseStr eam.Position is 3503, it has
increased by 1,024 Bytes! For all subsequent ReadLines,
fReader.BaseStr eam.Position does not change at all. Maybe I'm just not
quite understanding how the VB.NET StreamReader works... Does anyone
have an idea why this would be happening? Or maybe a better way to do
what I'm trying to do:
Jump to a position in a text file and read!
Comment