VBA - 连接字节数组

时间:2017-09-24 19:43:37

标签: arrays vba concatenation

我提到这个问题:PBKDF2 Excel UDF and how to concatenate INT(i)

OP没有为他的" ConcatenateArrayInPlace " -Function提供代码,该代码包含在他原始问题的自我解决方案中。我正在尝试自己创建这个功能。但是,我无处可去。

有人知道上述功能如何起作用吗?

最佳,

碧玉

2 个答案:

答案 0 :(得分:0)

我想我找到了解决方案。

我按如下方式更改了PBKDF2-Code:

outputBytes = ConcatenateArrayInPlace(outputBytes, tempBytes)

(而不是ConcatenateArrayInPlace outputBytes, tempBytes

我插入了以下功能:

Function ConcatenateArrayInPlace(ab1() As Byte, ab2() As Byte)
Dim ab3() As Byte
Dim i As Long

ab3 = ab1
ReDim Preserve ab3(UBound(ab1) + UBound(ab2))
For i = 0 To UBound(ab2)
    ab3(i + UBound(ab1)) = ab2(i)
Next

ConcatenateArrayInPlace = ab3

End Function

现在可行。

最佳,

碧玉

答案 1 :(得分:0)

我相信以下内容会复制丢失的代码:

Sub ConcatenateArrayInPlace(ByRef ab1() As Byte, ByRef ab2() As Byte)
    Dim origUBound As Long
    Dim i As Long
    origUBound = UBound(ab1)
    ReDim Preserve ab1(LBound(ab1) To origUBound + 1 + UBound(ab2) - LBound(ab2))
    For i = LBound(ab2) To UBound(ab2)
        ab1(origUBound + 1 + i - LBound(ab2)) = ab2(i)
    Next
End Sub

它将通过附加指定为第二个参数的数组来更新指定为第一个参数的数组。