我没有编写此vb6代码,但负责将其转换为vb.net。当我完成其余的应用程序转换时。我正在寻找使用Lset语句的方法,因为vb.net中不再支持它们。
Public Structure BigEndian
Dim b1 As Byte
Dim b2 As Byte
Dim b3 As Byte
Dim b4 As Byte
Dim b5 As Byte
Dim b6 As Byte
Dim b7 As Byte
Dim b8 As Byte
End Structure
Public Structure VBInteger <--This used to be Long in vb6
Dim Value As Integer <-- same here
End Structure
Private Function SwapBytes(theBytes() As Byte, index As Integer, Count As Integer)
Dim i As Integer
Dim ix As Integer
Dim result(Count) As Byte
Dim Bytes As BigEndian
Dim tmp As VBInteger
ix = Count - 1
For i = 0 To (Count - 1)
result(ix - i) = theBytes(index + i)
Next
Select Case Count
Case 4
Bytes.b4 = result(3)
Bytes.b3 = result(2)
Bytes.b2 = result(1)
Bytes.b1 = result(0)
LSet tmp = Bytes
SwapBytes = tmp.Value
Case 8
Bytes.b8 = result(7)
Bytes.b7 = result(6)
Bytes.b6 = result(5)
Bytes.b5 = result(4)
Bytes.b4 = result(3)
Bytes.b3 = result(2)
Bytes.b2 = result(1)
Bytes.b1 = result(0)
LSet tmp = Bytes
SwapBytes = tmp.Value
End Select
End Function
这将通过以下方式调用:
Private Function GetQInt32() As Integer
GetQInt32 = SwapBytes(Data, iStart, 4)
iStart = iStart + 4
End Function