I want to move data from a byte array to some kind of udt. I used copy memory to do it. But got some prob, really can't figure out why the result is like this:
Here is the code and the result:
please help me out. Your answer would be greatly appreciated.!!!Code:Private Type MyUdt1 count As Byte 'length of udt c(4) As Byte d As Byte End Type Private Type MyUdt2 count As Byte 'length of udt a As Byte b() As Byte End Type Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ (pDst As Any, pSrc As Any, ByVal ByteLen As Long) Private Sub Command1_Click() Dim arr(6) As Byte Dim udt1 As MyUdt1 Dim udt2 As MyUdt2 arr(0) = 5 arr(1) = 1 arr(2) = 2 arr(3) = 3 arr(4) = 4 arr(5) = 5 CopyMemory udt1, arr(0), 6 Debug.Print udt1.c(2) '=3,ok Debug.Print udt1.d '=0, why??? (it should be 5) ReDim udt2.b(0 To 2) CopyMemory ByVal udt2, arr(0), 6 Debug.Print udt2.a '=1, ok Debug.Print udt2.b(0) 'script out of range.??? End Sub




Reply With Quote