'递归调用子过程,aryInput 为需要进行处理的数组,GroupNum 为每个组合的元素数目,其他参数第一次调用时不必传入
Private Sub test(aryInput As Variant, ByVal GroupNum As Integer, Optional ByVal Workinggroup As Integer = 1, Optional ByVal WorkingPointer As Integer = 0, Optional ByVal WorkingStr As String)
Dim i As Integer
If Workinggroup > GroupNum Then
Debug.Print WorkingStr '结果输出
Exit Sub
End If
For i = LBound(aryInput) + WorkingPointer To UBound(aryInput)
test aryInput, GroupNum, Workinggroup + 1, i + 1, WorkingStr & aryInput(i) & " "
Next
End Sub
for i1=1 to 8
for i2=i1+1 to 9
for i3=i2+1 to 10
for i4=i3+1 to 11
for i5=i4+1 to 12
s=cstr(i1)+" "+cstr(i2)+" "+cstr(i3)+" "+cstr(i4)+" "+cstr(i5)
debug.print s
Next i5
Next i4
Next i3
Next i2
Next i1