VBGamer |
|||||||||||||||||||||||||||
RE: CopyMemory Adam Hoult (1 reply, 0 views) (2000-Jun-24) Hey dan,
First of all define this in a Module
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Now imagine you had an array with 100,000 Long's in it, and you wanted to copy the entire array into another array
So here is our original array
Dim MyArray(100000) as Long
Now we will copy it into a temporary array
Dim TempArray() as Long
Redim TempArray(100000)
CopyMemory TempArray(0), MyArray(0), 100000 * 4 'Remember a long is 4 bytes
Ok so what do you do if you want to copy 5000 elements, from the array starting at element 1000 ??
Dim TempArray() as Long
Redim TempArray(5000)
CopyMemory TempArray(0), MyArray(1000), 5000 *4
The TempArray is now filled with 5000 values taken from the original array starting at element 1000
It can be used for pretty much anything, you want, just remember that you have to know the length in bytes of the type of object you are copying. For example if we were copying an array of UDT's
Type
Byte1 as Byte
Long1 as Long
Integer1 as Integer
End Type
This will equal 7 bytes so simply use NumberOfElements*7 instead of *4 as in our above example
HTH
Adam
|