[vba] JoinBytesArray 함수를 이용한 Byte 조인하기

하나를하더라도최선을 2021-08-09 14:07:41 32,328 0 0
'// Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal cbLength As Long)
 
 
Public Function JoinBytesArray(ParamArray ByteArrays() As Variant) As Byte()
    Dim sizeArray As Variant, startIndex As Long, i As Integer
    Dim Buffer() As Byte, ByteArray() As Byte
    ReDim sizeArray(0 To UBound(ByteArrays))
    For i = 0 To UBound(ByteArrays)
        sizeArray(i) = UBound(ByteArrays(i))
    Next
    
    startIndex = 0
    ReDim Buffer(WorksheetFunction.Sum(sizeArray) + UBound(sizeArray))
    For i = 0 To UBound(ByteArrays)
        ByteArray = ByteArrays(i)
        CopyMemory Buffer(startIndex), ByteArray(0), UBound(ByteArray) + 1
        startIndex = startIndex + UBound(ByteArray) + 1
    Next
    JoinBytesArray = Buffer
End Function
 
Private Function Sum(ByVal IntegerArray As Variant) As Long
    Dim i As Integer
    For i = 0 To UBound(IntegerArray)
        Sum = Sum + Val(IntegerArray(i))
    Next
    '// Range.Application.WorksheetFunction.Sum
End Function
 

댓글 0개

첫 번째 댓글을 작성해보세요!