Thursday, June 7, 2012

VB6 Code - Meng-copy Array Secara Cepat

Private Declare Sub CopyMemory Lib "kernel32" _ 
Alias "RtlMoveMemory" (Dest As Any, _
Source As Any, ByVal Length As Long)

Private Sub
CopyArray()
Dim lngbytes As Long
Dim
lngSrc(1 To 600000) As Long
Dim
lngDest(1 To 600000) As Long
'
' Number of bytes equals number of array
' elements times the element length.
'
lngbytes = (UBound(lngSrc) - LBound(lngSrc) + 1) * Len(lngSrc(1))
'
' Copy the array passing the address of the start to
' the destination and source arrays and the length
' of the arrays.
'
Call CopyMemory(lngDest(LBound(lngDest)), lngSrc(LBound(lngSrc)), lngbytes)
End Sub