简体   繁体   English

VBA-串联字节数组

[英]VBA - concatenate byte array

I refer to this question: PBKDF2 Excel UDF and how to concatenate INT(i) 我指的是这个问题: PBKDF2 Excel UDF和如何连接INT(i)

OP did not provide the code for his " ConcatenateArrayInPlace "-Function, which is contained in his self-found solution to his original question. OP未提供其“ ConcatenateArrayInPlace ” -Function的代码,该代码包含在他对原始问题的自助式解决方案中。 I am trying to create the function myself. 我正在尝试自己创建函数。 However, I'm getting nowhere. 但是,我无处可去。

Does anybody know how the above-mentioned function might work? 有人知道上述功能如何工作吗?

Best, 最好,

Jasper 碧玉

I think I found a solution. 我想我找到了解决方案。

I changed the PBKDF2-Code as follows: 我将PBKDF2-Code更改如下:

outputBytes = ConcatenateArrayInPlace(outputBytes, tempBytes)

(Instead of ConcatenateArrayInPlace outputBytes, tempBytes ) (而不是ConcatenateArrayInPlace outputBytes, tempBytes

I inserted the following function: 我插入了以下功能:

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

Now it works. 现在可以了。

Best, 最好,

Jasper 碧玉

I believe that the following would replicate the missing code: 我相信以下内容将复制丢失的代码:

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

It will update the array specified as the first parameter by appending the array specified as the second parameter. 它将通过追加指定为第二个参数的数组来更新指定为第一个参数的数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM