|
-
Dec 17th, 2011, 08:48 AM
#1
Thread Starter
New Member
[RESOLVED] FileStream, ReadBytes with interval
I'm trying to read bytes with 1200 interval for 100 times, but I can't get it working. This is my code:
Code:
Try
Dim fr As FileStream = File.OpenRead(OpenFileDialog1.FileName)
Dim data(fr.Length) As Byte
Using reader As New BinaryReader(fr)
Const START As Long = 4896
fr.Seek(START, SeekOrigin.Begin)
data = reader.ReadBytes(data.Length)
End Using
ListBox1.Items.Add(System.Text.Encoding.UTF8.GetString(data))
fr.Close()
Catch
End Try
I need to read from offset 4896, then from 6096, then from 7296 for 100 times and for each interval add to the listbox. who can help me? Thanks
Last edited by rossi_4656; Dec 20th, 2011 at 08:13 AM.
Sorry for my bad english 
-
Dec 17th, 2011, 01:57 PM
#2
Re: FileStream, ReadBytes with interval
I dont get it.....is that code executed by a timer ? What exactly is it doing that its not supposed to ?
Need more information.
-
Dec 19th, 2011, 07:09 AM
#3
Thread Starter
New Member
Re: FileStream, ReadBytes with interval
No this code is executed by a button, and I need to read data from offset 4896, then 6096, then 7296... for 100 times. The interval is offset 1200.
Example for read data to offset 4896 and then to 6096 and add those 2 items to listbox:
Code:
Button1.Click........
Try
Dim fr As FileStream = File.OpenRead(OpenFileDialog1.FileName)
Dim data(fr.Length) As Byte
Using reader As New BinaryReader(fr)
Const START As Long = 4896
fr.Seek(START, SeekOrigin.Begin)
data = reader.ReadBytes(data.Length)
End Using
ListBox1.Items.Add(System.Text.Encoding.UTF8.GetString(data))
fr.Close()
Catch
End TryTry
Dim fr As FileStream = File.OpenRead(OpenFileDialog1.FileName)
Dim data(fr.Length) As Byte
Using reader As New BinaryReader(fr)
Const START As Long = 6096
fr.Seek(START, SeekOrigin.Begin)
data = reader.ReadBytes(data.Length)
End Using
ListBox1.Items.Add(System.Text.Encoding.UTF8.GetString(data))
fr.Close()
Catch
End Try
Regular offset interval = 1200
But it's hard to do if I want to read 100 datas so I'm looking for a fast way
Sorry for my bad english 
-
Dec 19th, 2011, 07:22 AM
#4
Re: FileStream, ReadBytes with interval
Did soem changes to make a 100* Times Loop to step through the Stream. No checking for EndOfStream
Is that assingment to a new ListBox1.Item correct? (Only the last value of Data, not the previous ones?)
Vb.Net Code:
Try
Dim fr As FileStream = File.OpenRead("test.txt")
Dim data(fr.Length) As Byte
Using reader As New BinaryReader(fr)
Dim START As Long = 4896
Dim i As Integer = 0
Do
fr.Seek(START, SeekOrigin.Begin)
data = reader.ReadBytes(data.Length)
START += 1200
i += 1
Loop Until i = 100 ' do loop is done 100 times!
fr.Seek(START, SeekOrigin.Begin)
data = reader.ReadBytes(data.Length)
End Using
ListBox1.Items.Add(System.Text.Encoding.UTF8.GetString(data))
fr.Close()
Catch
End Try
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Dec 20th, 2011, 08:10 AM
#5
Thread Starter
New Member
Re: FileStream, ReadBytes with interval
 Originally Posted by opus
Did soem changes to make a 100* Times Loop to step through the Stream. No checking for EndOfStream
Is that assingment to a new ListBox1.Item correct? (Only the last value of Data, not the previous ones?)
Vb.Net Code:
Try
Dim fr As FileStream = File.OpenRead("test.txt")
Dim data(fr.Length) As Byte
Using reader As New BinaryReader(fr)
Dim START As Long = 4896
Dim i As Integer = 0
Do
fr.Seek(START, SeekOrigin.Begin)
data = reader.ReadBytes(data.Length)
START += 1200
i += 1
Loop Until i = 100 ' do loop is done 100 times!
fr.Seek(START, SeekOrigin.Begin)
data = reader.ReadBytes(data.Length)
End Using
ListBox1.Items.Add(System.Text.Encoding.UTF8.GetString(data))
fr.Close()
Catch
End Try
Thanks for the code, but I need to read also previews data. Anyway I've made some changes and I've resolved, thank you very much!
This is the working code:
Code:
Try
Dim fr As FileStream = File.OpenRead(OpenFileDialog1.FileName)
Dim data(fr.Length) As Byte
Using reader As New BinaryReader(fr)
Dim START As Long = 4896
Dim i As Integer = 0
Do
START += 1200
i += 1
fr.Seek(START, SeekOrigin.Begin)
data = reader.ReadBytes(data.Length)
ListBox1.Items.Add(System.Text.Encoding.UTF8.GetString(data))
Loop Until i = 100 ' do loop is done 100 times!
End Using
fr.Close()
Catch
End Try
Sorry for my bad english 
-
Dec 20th, 2011, 08:47 AM
#6
Re: FileStream, ReadBytes with interval
 Originally Posted by rossi_4656
Thanks for the code, but I need to read also previews data. Anyway I've made some changes and I've resolved, thank you very much!
This is the working code:
Code:
Try
Dim fr As FileStream = File.OpenRead(OpenFileDialog1.FileName)
Dim data(fr.Length) As Byte
Using reader As New BinaryReader(fr)
Dim START As Long = 4896
Dim i As Integer = 0
Do
START += 1200
i += 1
fr.Seek(START, SeekOrigin.Begin)
data = reader.ReadBytes(data.Length)
ListBox1.Items.Add(System.Text.Encoding.UTF8.GetString(data))
Loop Until i = 100 ' do loop is done 100 times!
End Using
fr.Close()
Catch
End Try
In my humble opinion you are not reading any PREVIOUS data with your code, you start to read from byte# 6096!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Dec 20th, 2011, 09:50 AM
#7
Thread Starter
New Member
Re: FileStream, ReadBytes with interval
 Originally Posted by opus
In my humble opinion you are not reading any PREVIOUS data with your code, you start to read from byte# 6096!
Well, I've tryed the code and it's working . Anyway my datas are hex values, maybe this is the reason that the code it's working 
Example data at offset 6096:
Code:
56 41 4C 55 45 20 31 00 00
So the program read from offset 6096 to 7002, then loop to offset 7296 (+1200)
Sorry for my bad english 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|