get2noesks
New Member
- Joined
- Jul 15, 2015
- Messages
- 24
Code is not recognising the highlighted line where CopyMemory is called. How do we implement it?
Rich (BB code):
Public Sub Merge(list() As String, ByVal beginning As Integer, ByVal middle As Integer, ByVal ending As Integer)
Dim temp_array() As String
Dim temp As Integer
Dim counterA As Integer
Dim counterB As Integer
Dim counterMain As Integer
' Copy the array into a temporary array.
ReDim temp_array(beginning To ending)
CopyMemory temp_array(beginning), list(beginning), (ending - beginning + 1) * Len(list(beginning))
' counterA and counterB mark the next item to save
' in the first and second halves of the list.
counterA = beginning
counterB = middle + 1
' counterMain is the index where we will put the
' next item in the merged list.
counterMain = beginning
Do While (counterA <= middle) And (counterB <= ending)
' Find the smaller of the two items at the front
' of the two sublists.
If (temp_array(counterA) <= temp_array(counterB)) _
Then
' The smaller value is in the first half.
list(counterMain) = temp_array(counterA)
counterA = counterA + 1
Else
' The smaller value is in the second half.
list(counterMain) = temp_array(counterB)
counterB = counterB + 1
End If
counterMain = counterMain + 1
Loop
' Copy any remaining items from the first half.
If counterA <= middle Then
CopyMemory list(counterMain), temp_array(counterA), (middle - counterA + 1) * Len(list(beginning))
End If
' Copy any remaining items from the second half.
If counterB <= ending Then
CopyMemory list(counterMain), temp_array(counterB), (ending - counterB + 1) * Len(list(beginning))
End If
End Sub