Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long) Dim a As Date Dim b(3) As Byte Private Sub Form_Load() CopyMemory b(0), a, Len(a) End Sub
不好意思,忘记给a赋值了 Private Sub Form_Load() a = Now CopyMemory b(0), a, Len(a) End SubCopyMemory 的说明 The CopyMemory function copies a block of memory from one location to another.?Destination Points to the starting address of the copied block抯 destination.?Source Points to the starting address of the block of memory to copy.?Length Specifies the size, in bytes, of the block of memory to copy.
那我如何将数组中的值再读出来保存到Date变量中去呢?
反过来啊 dim c as date CopyMemory c, b(0), Len(c)
CopyMemory 楼上该说的都说了,只好来蹭点分
bobbyxby(i386) 的代码好像有点问题,应该是这样的: Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long) Dim a As Date Dim b(3) As Byte Private Sub Form_Load() a=now CopyMemory varptr(b(0)), varptr(a), Len(a) End Sub
不好意思CopyMemory函数中指针是不能按引用传递的,必须安值传递,所以代码应该是这样的Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long) Dim a As Date Dim b(3) As Byte Private Sub Form_Load() a=now CopyMemory byval varptr(b(0)), byval varptr(a), Len(a) End Sub另:VB中的数组是SafeArray,它与C中的数组是不一样的,必须用VarPtr函数才能获得b(0)的真正地址
Non, non, non!!! A Date var. is 8-bytes long (double)! try: dim x as date debug.print lenb(x)
I am very very sorry that our code leads to the same result,i really dont know what's the difference(to James0001(虾米—什么时候成大虾?) ) lenb and len gets the same val try the following samplePrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long) Dim a As Date Dim d As Date Dim b(3) As Byte Dim c(3) As Byte Private Sub Form_Click() Me.AutoRedraw = True Me.Cls a = Now CopyMemory ByVal VarPtr(b(0)), ByVal VarPtr(a), LenB(a) For i = 0 To 3 Me.Print b(i) Next i CopyMemory c(0), a, Len(a) For i = 0 To 3 Me.Print c(i) Next i CopyMemory d, c(0), LenB(d) MsgBox a MsgBox d MsgBox Len(a) MsgBox LenB(a) End Subwin2003 vb6 sp6using vb ,you should bypass some boring things or use c
Dim a As Date
Dim b(3) As Byte
Private Sub Form_Load()
CopyMemory b(0), a, Len(a)
End Sub
Private Sub Form_Load()
a = Now
CopyMemory b(0), a, Len(a)
End SubCopyMemory 的说明
The CopyMemory function copies a block of memory from one location to another.?Destination
Points to the starting address of the copied block抯 destination.?Source
Points to the starting address of the block of memory to copy.?Length
Specifies the size, in bytes, of the block of memory to copy.
dim c as date
CopyMemory c, b(0), Len(c)
楼上该说的都说了,只好来蹭点分
Dim a As Date
Dim b(3) As Byte
Private Sub Form_Load()
a=now
CopyMemory varptr(b(0)), varptr(a), Len(a)
End Sub
Dim a As Date
Dim b(3) As Byte
Private Sub Form_Load()
a=now
CopyMemory byval varptr(b(0)), byval varptr(a), Len(a)
End Sub另:VB中的数组是SafeArray,它与C中的数组是不一样的,必须用VarPtr函数才能获得b(0)的真正地址
try:
dim x as date
debug.print lenb(x)
lenb and len gets the same val
try the following samplePrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Dim a As Date
Dim d As Date
Dim b(3) As Byte
Dim c(3) As Byte
Private Sub Form_Click()
Me.AutoRedraw = True
Me.Cls
a = Now
CopyMemory ByVal VarPtr(b(0)), ByVal VarPtr(a), LenB(a)
For i = 0 To 3
Me.Print b(i)
Next i
CopyMemory c(0), a, Len(a)
For i = 0 To 3
Me.Print c(i)
Next i
CopyMemory d, c(0), LenB(d)
MsgBox a
MsgBox d
MsgBox Len(a)
MsgBox LenB(a)
End Subwin2003 vb6 sp6using vb ,you should bypass some boring things or use c