I'm still trying to learn how to use this the right way, I thought I knew how, but apparently not.![]()
The first problem is now I'm getting an "Out of memory error" with this code.
It will probably be easier just to paste this into VB so you can see the code and test it.
Warning: This might crash the VB IDE so be warned. Or look @ the code before running it in case I'm doing something seriously wrong.
In a module:
In a form:Code:Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) 'Append one byte array to another byte array. Public Sub AppendByteToByte(Destination() As Byte, Source() As Byte) Dim lonSrcLen As Long Dim lonDestLen As Long Dim lonNewLen As Long lonSrcLen = SafeUBByte(Source()) lonDestLen = SafeUBByte(Destination) lonNewLen = lonDestLen + lonSrcLen Debug.Print lonNewLen ReDim Preserve Destination(0 To lonNewLen) As Byte CopyMemory Destination(lonDestLen), Source(0), lonNewLen End Sub 'UBound function with local error handling. Private Function SafeUBByte(ByteArray() As Byte) As Long On Error GoTo ErrorHandler SafeUBByte = UBound(ByteArray()) Exit Function ErrorHandler: SafeUBByte = 0 Exit Function End Function 'LBound function with local error handling. Private Function SafeLBByte(ByteArray() As Byte) As Long On Error GoTo ErrorHandler SafeLBByte = LBound(ByteArray()) Exit Function ErrorHandler: SafeLBByte = 0 Exit Function End Function
Code:Private Sub Form_Load() Dim bytTest() As Byte, s As String Dim bytSrc() As Byte bytSrc = StrConv("1234", vbFromUnicode) AppendByteToByte bytTest, bytSrc AppendByteToByte bytTest, bytSrc AppendByteToByte bytTest, bytSrc AppendByteToByte bytTest, bytSrc AppendByteToByte bytTest, bytSrc AppendByteToByte bytTest, bytSrc AppendByteToByte bytTest, bytSrc s = StrConv(bytTest, vbUnicode) Debug.Print s & " (" & Len(s) & ")" End Sub





Reply With Quote