|
-
Feb 27th, 2008, 05:37 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] FileStrem.Read
Well i have this code:
vb Code:
Dim File As New IO.FileStream(OpenFile.FileName, IO.FileMode.Open)
Dim BytesComentario(41) As Byte
File.Read(BytesComentario, 11, 42)
When I run the code OpenFile.FileName is not null, and the file that it points to exists. And this file lenth is about 150 bytes.
Still I get this error on the third line:
"Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection."
And I really can't understand why, because i see nothing wrong.
-
Feb 27th, 2008, 06:17 PM
#2
Junior Member
Re: [2005] FileStrem.Read
Code:
Dim File As New IO.FileStream(OpenFile.FileName, IO.FileMode.Open)
Dim BytesComentario(41+11) As Byte
File.Read(BytesComentario, 11, 42)
-
Feb 27th, 2008, 06:28 PM
#3
Thread Starter
Fanatic Member
Re: [2005] FileStrem.Read
but by doing that the byte array will be bigger.
Let me explain what I want the code to do:
Read to a array (BytesComentario) 42 bytes starting at index 11.
Example: you have a file like this:
Code:
2A 2A BC 00 00 00 01 02 05 AC 05 03 04 05 F4 AB 2B 3F 9C
And I want to read 5 bytes starting on index 9 to a array of bytes. So in that array I should get
-
Feb 27th, 2008, 06:31 PM
#4
Re: [2005] FileStrem.Read
The reason for the error is that you are setting an offset of eleven in the array then trying to fill the array with 42 elements so the array would have to be 41 + 11 like VladC# says but that would give you 11 empty elements at the start of the array which you dont want. I think what you need to do is to use Seek or Position to set the position in the stream to start reading from and just use no offset.
Casey.
-
Feb 27th, 2008, 06:54 PM
#5
Thread Starter
Fanatic Member
Re: [2005] FileStrem.Read
Thks a lot I used position and it worked. I've tried to used it before and also seek but didnt work, now I found why i still used the offset.
But by the description they give on the offset my code should work.
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
|