Witam,

Mam do zrobienia mergesort w VBA, że tak działam bardzo po omacku bo nie znam VBA prosze o pomoc:

Wyrzuca mi out of stack error 28.
Kod zroboiony wg algorytmu.
Moj kod:

 
Sub MSort(l, p)
Dim middle As Long

If (N > l) Then
middle = (l + N) \ 2
MSort l, s
MSort s + 1, N

Scal l, s, N
End If
WypiszWyniki

End Sub
Sub Scal(l, p, s)

Dim temp As Integer
Dim counterA As Double
Dim counterB As Double
Dim counterMain As Double

ReDim R(beginning To ending)
CopyMemory R(beginning), list(beginning), _
(ending - beginning + 1) * Len(T(beginning))
counterA = beginning
counterB = s + 1

counterMain = beginning
Do While (counterA <= s) And (counterB <= ending)
If (R(counterA) <= R(counterB)) _
Then

T(counterMain) = R(counterA)
counterA = counterA + 1
Else
T(counterMain) = R(counterB)
counterB = counterB + 1
End If
counterMain = counterMain + 1
Loop


If counterA <= s Then
CopyMemory T(counterMain), R(counterA), _
(s - counterA + 1) * Len(T(beginning))
End If


If counterB <= ending Then
CopyMemory T(counterMain), R(counterB), _
(ending - counterB + 1) * Len(T(beginning))
End If

End Sub