VB Code:
Option Explicit
Private Row() As String
Private Sub Command1_Click()
CalculatePerms 5, 3
End Sub
Private Sub CalculatePerms(ByRef NoOfItems As Long, ByRef ItemsPerPerm As Long)
ReDim Row(ItemsPerPerm - 1)
Combinations 0, NoOfItems, 0, ItemsPerPerm - 1
End Sub
Private Sub Combinations(Start As Long, NoOfItems As Long, NodeIndex As Long, ItemsPerPerm As Long)
Dim Index As Long
If NodeIndex > ItemsPerPerm Then
'at this point here, the Row array holds the indexes of the items in this combination
MsgBox Join$(Row, ",")
Else
For Index = Start To NoOfItems
Row(NodeIndex) = "Item: " & CStr(Index)
'recursively generate combinations from i+1...n
Call Combinations(Index + 1, NoOfItems, NodeIndex + 1, ItemsPerPerm)
Next
End If
End Sub