VB Code:
Private Sub cmdAddsTo2_Click()
Dim MyStartTick As Long
Dim MyEndTick As Long
Dim MyI As Integer
Dim MyCounter As Long
'Lets do 61 elements
Dim MySourceArr() As Integer
ReDim MySourceArr(60)
For MyI = 0 To 60
MySourceArr(MyI) = MyI + 1
Next MyI
'taken 6 at a time
Dim My4_arr() As Integer
ReDim My4_arr(5)
'that adds to 150
Dim ItAddsTo As Long
ItAddsTo = 150
MyCounter = 0
MyStartTick = GetTickCount
Call YOUR_SUB_OR_FUNCTION_HERE(MySourceArr, My4_arr, MyCounter, _
ItAddsTo, ...[i]anything else you need[/i])
MyEndTick = GetTickCount
MsgBox MyCounter & " Took " & (MyEndTick - MyStartTick) / 1000
End Sub
VB Code:
Private Sub NUM_SUM_COMBS_2(ByRef IN_Arr() As Integer, _
ByRef HowDeep As Integer, ByVal MyLev As Integer, _
ByRef MyOut() As Integer, ByRef MyCount As Long, _
ByRef MyLastI As Integer, ByVal mAddsTo As Integer, _
ByRef mBackOut As Boolean)
'mylev starts at 0, and so does mycount
If MyLev > HowDeep Then
If mAddsTo = 0 Then
MyCount = MyCount + 1 'At this point, MyOut() contains a combination
End If 'of elements that add to the desired sum
Else
'does something
Dim MyI As Integer
For MyI = (MyLastI) To (UBound(IN_Arr) - MyLev)
'does something else
Call NUM_SUM_COMBS_2(IN_Arr, HowDeep, MyLev + 1, MyOut, MyCount, _
MyI, mAddsTo - MyOut(MyLev), mBackOut)
'does some more stuff
Next MyI
End If
End Sub