字节数组在VB6一个符号整数(Byte Array to a Signed Integer in V

2019-07-03 17:27发布

我无法从字节数组转换为一个有符号整数VB6。 这将是简单的用BitConverter在.NET做,但我不知道做什么用VB6做。 谢谢

Answer 1:

不幸的是没有内置的功能,你需要写一个。 这里是让你开始一个快速的样品。

Private Function BArrayToInt(ByRef bArray() As Byte) As Integer
    Dim iReturn As Integer
    Dim i As Integer

    For i = 0 To UBound(bArray) - LBound(bArray)
        iReturn = iReturn + bArray(i) * 2 ^ i
    Next i

    BArrayToInt = iReturn

End Function


Answer 2:

CopyMemory的

航空代码(可能会崩溃您的电脑,导致恐龙的攻击等)。

Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, _ source As Any, ByVal bytes As Long)  

Dim a() As Byte 
Dim n As Integer 
 'get the bytes somehow into a()
CopyMemory n, a(0), 2 


文章来源: Byte Array to a Signed Integer in VB6
标签: vb6 bytearray