terabin Posted February 27, 2013 Author Share Posted February 27, 2013 I having problems…Vb6 version```Public Function ReadBytes(ByVal nLength As Long, Optional MoveReadHead As Boolean = True) As Byte()Dim Data() As Byte If nLength = 0 Then Exit Function If ReadHead + nLength - 1 > BufferSize Then Exit Function ReDim Data(nLength - 1) CopyMemory Data(0), Buffer(ReadHead), nLength If MoveReadHead Then ReadHead = ReadHead + nLength ReadBytes = DataEnd Function```My Vb.net Version``` Public Function ReadBytes(ByVal nLength As Integer, Optional ByVal MoveReadHead As Boolean = True) As Byte() Dim Data() As Byte If nLength = 0 Then Return Nothing If ReadHead + nLength - 1 > BufferSize Then Return Nothing ReDim Data(nLength - 1) For i As Integer = 0 To ReadHead + nLength - 1 Data(i) = Buffer(i) Next If MoveReadHead Then ReadHead += nLength Return Data End Function```Error:"Index was outside the bounds of the array" Link to comment Share on other sites More sharing options...
abhi2011 Posted February 27, 2013 Share Posted February 27, 2013 This is the wrong board. There is a programming board for this.But here is a chunk of code that works.```Public Function ReadBytes(ByVal nLength As Long, Optional ByVal MoveReadHead As Boolean = True) As Byte() Dim Data() As Byte If nLength = 0 Then Return Nothing If ReadHead + nLength - 1 > BufferSize Then Return Nothing ReDim Data(nLength - 1) CopyMemory(Data(0), Buffer(ReadHead), nLength) If MoveReadHead Then ReadHead = ReadHead + nLength ReadBytes = Data End Function```Btw declare this```Public Declare Auto Sub CopyMemory Lib "Kernel32.dll" Alias "RtlMoveMemory" (ByVal Destination As Object, ByVal Source As Object, ByVal Length As Long)``` Link to comment Share on other sites More sharing options...
terabin Posted February 28, 2013 Author Share Posted February 28, 2013 That did not work … Link to comment Share on other sites More sharing options...
abhi2011 Posted February 28, 2013 Share Posted February 28, 2013 Where is the error generated.I really can't help you much. The real Vb.net guys can, like Budweiser. Link to comment Share on other sites More sharing options...
XerShade Posted February 28, 2013 Share Posted February 28, 2013 Just a question but WHY THE HELL ARE YOU USING CopyMemory, .Net has functions to handle byte arrays a lot more safely then copying it to and from RAM. Link to comment Share on other sites More sharing options...
terabin Posted February 28, 2013 Author Share Posted February 28, 2013 My knowledge in vb.net is limited… Link to comment Share on other sites More sharing options...
XerShade Posted March 2, 2013 Share Posted March 2, 2013 Here http://www.touchofdeathforums.com/community/index.php?/topic/132165-vbnet-byte-arrays/ Link to comment Share on other sites More sharing options...
abhi2011 Posted March 4, 2013 Share Posted March 4, 2013 > My knowledge in vb.net is limited… Link to comment Share on other sites More sharing options...
Mal Posted March 5, 2013 Share Posted March 5, 2013 > Here [http://www.touchofde…et-byte-arrays/](http://www.touchofdeathforums.com/community/index.php?/topic/132165-vbnet-byte-arrays/)I've added an open-source example and library that contains extension methods (all you'll ever need for Byte Arrays) to Xershade's topic. It's in C# 5, but you can use http://www.developerfusion.com/tools/convert/csharp-to-vb/ to convert C# to VB.NET. Link to comment Share on other sites More sharing options...
XerShade Posted March 5, 2013 Share Posted March 5, 2013 > I've added an open-source example and library that contains extension methods (all you'll ever need for Byte Arrays) to Xershade's topic. It's in C# 5, but you can use http://www.developerfusion.com/tools/convert/csharp-to-vb/ to convert C# to VB.NET.Your code is not needed, the example I posted is already done in VB.Net, and why would he want the C# source if the doesn't know C# to begin with. Link to comment Share on other sites More sharing options...
Mal Posted March 5, 2013 Share Posted March 5, 2013 > Your code is not needed, the example I posted is already done in VB.Net, and why would he want the C# source if the doesn't know C# to begin with.It's going to remain there until someone removes it. Regardless of whether it is needed or not it gives individuals an option. You failed to produce the code for the library that shows them how to do what they wanted to do, so I covered for you. Don't get all pissy and throw a fit because you felt like I was stepping on your toes, and then still honestly don't have much of a clue as to what you're talking about with objects and constructors; I thought it was all pretty silly.It's rude to bite the hand that's provided help in the absence of it. Learn something from what I provided. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now