'Example Name:CopyMemory
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim sSave As String, Cnt As Long, T As Long, Pos As Long, Length As Long
Const mStr = "Hello "
Length = Len(mStr)
sSave = Space(5000 * Length) 'make buffer for justified comparison
'Get the current tickcount
T = GetTickCount
Pos = 1
sSave = Space(5000 * Length)
For Cnt = 1 To 5000
Mid(sSave, Pos, Length) = mStr
Pos = Pos + Length
Next Cnt
'Show the results
MsgBox "It took Visual basic" + Str$(GetTickCount - T) + " msecs. to add 5000 times a string to itself."
'Get the current tickcount
T = GetTickCount
Pos = 0
sSave = Space(5000 * Length)
For Cnt = 1 To 5000
CopyMemory ByVal StrPtr(sSave) + Pos, ByVal StrPtr(mStr), LenB(mStr)
Pos = Pos + LenB(mStr)
Next Cnt
'Show the results
MsgBox "It took CopyMemory" + Str$(GetTickCount - T) + " msecs. to add 5000 times a string to itself."
End Sub