cpopham Posted January 8, 2006 Posted January 8, 2006 Okay, here is my code: Dim msNewStream As New MemoryStream Dim msstreamhass As New MemoryStream msNewStream.Write(msStream.ToArray, 0, msStream.Length - (hashsize * 8)) Dim intP As Integer = msStream.Length - (hashsize * 8) intP = msStream.Length msStream.Position = 0 msstreamhass.Write(msStream.ToArray, (msStream.Length - 159), msStream.Length) The first part works fine "msNewStream.Write(msStream.ToArray, 0, msStream.Length - (hashsize * 8))" The second one always throws an exception of: 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. Anyone have any ideas? Thanks, Chester Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
Administrators PlausiblyDamp Posted January 9, 2006 Administrators Posted January 9, 2006 Not sure if there is a bug in the lines Dim intP As Integer = msStream.Length - (hashsize * 8) intP = msStream.Length as you are assigning to intP in both cases but never using it in between. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Cags Posted January 9, 2006 Posted January 9, 2006 As you say PlausiblyDamp they are not using intP between the assigments. But intP isn't actually being used at all in the code provided so I'm assuming that isn't whats causing your application to crash. When you say the second part causes in error, are you refering to the line msstreamhass.Write(msStream.ToArray, (msStream.Length - 159), msStream.Length) For now I'm going to go ahead and assume this is the line throwing the error. There are 3 parameters being passed in a buffer, a start point and a length. For now lets ignore the buffer and look at the other 2 values. You are specifying the start point as 159 places before the end of the stream and then specifying the length as the full length of the stream. I'm assuming this is going to cause an error but I've never used a memorystream so I can't say for certain. If the aim is to get only the last section of the stream I would suggest what you try this instead... msstreamhass.Write(msStream.ToArray, (msStream.Length - 159), 159) Quote Anybody looking for a graduate programmer (Midlands, England)?
cpopham Posted January 10, 2006 Author Posted January 10, 2006 I have changed my method of working the problem and it is working fine now. I was using intP as merely a check when stepping through the code. I just wanted to see what values were there and was not actually using the variable for anything. I now have a new problem though that is dealing with this same application, but this one is for hashing so I will start a new thread on it. But thanks for the help :) Chester Quote ____________________________________________ http://www.pophamcafe.com I am starting a developers section, more tutorials than anything.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.