主题:[讨论]请教个关于内存的问题!
以下过程功能是想拷贝数组
1.帮忙看看一下代码,为什么只有getF是正确的,还有其他办法吗?
2.另外getA--getE是怎么解释的?
Option Explicit
Dim X(0 To 1) As Byte
Dim Y(0 To 1) As Byte
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Form_Load()
X(0) = 5
X(1) = 6
getA VarPtr(X(0))
getB X
getC X
getD X(0)
getE X
getF VarPtr(Y(0)), VarPtr(X(0))
End Sub
Sub getA(ByVal Z As Long)
CopyMemory Y(0), Z, 2
Debug.Print Y(0); Y(1)
End Sub
Sub getB(Z)
CopyMemory Y(0), Z, 2
Debug.Print Y(0); Y(1)
End Sub
Sub getC(Z)
CopyMemory Y(0), Z(0), 2
Debug.Print Y(0); Y(1)
End Sub
Sub getD(Z)
CopyMemory Y(0), Z, 2
Debug.Print Y(0); Y(1)
End Sub
Sub getE(Z)
Debug.Print VarPtr(Z); VarPtr(Z(0))
End Sub
Sub getF(Z1 As Long, Z2 As Long)
CopyMemory ByVal Z1, ByVal Z2, 2
Debug.Print Y(0); Y(1)
End Sub
1.帮忙看看一下代码,为什么只有getF是正确的,还有其他办法吗?
2.另外getA--getE是怎么解释的?
Option Explicit
Dim X(0 To 1) As Byte
Dim Y(0 To 1) As Byte
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Form_Load()
X(0) = 5
X(1) = 6
getA VarPtr(X(0))
getB X
getC X
getD X(0)
getE X
getF VarPtr(Y(0)), VarPtr(X(0))
End Sub
Sub getA(ByVal Z As Long)
CopyMemory Y(0), Z, 2
Debug.Print Y(0); Y(1)
End Sub
Sub getB(Z)
CopyMemory Y(0), Z, 2
Debug.Print Y(0); Y(1)
End Sub
Sub getC(Z)
CopyMemory Y(0), Z(0), 2
Debug.Print Y(0); Y(1)
End Sub
Sub getD(Z)
CopyMemory Y(0), Z, 2
Debug.Print Y(0); Y(1)
End Sub
Sub getE(Z)
Debug.Print VarPtr(Z); VarPtr(Z(0))
End Sub
Sub getF(Z1 As Long, Z2 As Long)
CopyMemory ByVal Z1, ByVal Z2, 2
Debug.Print Y(0); Y(1)
End Sub