Michael,
I am not sure I quite follow your post?
Besides, I finally figured out how to accomplish what I wanted to do. And it works....
Here is the code:
=======================
Public Sub Combinations(numbers() As Long, p As Long, NumComboLabel As Label, Combinations As ListView)
'It outputs the number of different combinations to a listview control that was passed
'to it as well as putting out the number of combinations to the label that was passed to it
'The number of combinations is calculated
'according to the formula n_choose_p = n!/p!(n-p)!
Dim n As Long
Dim temp As Integer
n = UBound(numbers)
temp = LBound(numbers)
n = n - temp + 1 'the number of elements in the array
'================================
'make sure there is no illegal input
If p > n Or n < 1 Or p < 1 Then
MsgBox "Illegal input in the Combinations function!", vbExclamation, "Error"
Exit Sub
End If
'================================
Dim NumCombo As Long
NumCombo = numCombinations(n, p) 'the number of possible combinations
NumComboLabel.Caption = "The Number of Combinations are: " & NumCombo
'Dim combo() As Long
'ReDim combo(temp To p)
'=========================
'indices
Dim i As Integer
Dim x As Integer
Dim y As Integer
Dim indices() As Integer
ReDim indices(p)
'=======================
CreateHeader Combinations, p
'========================
'initialize the indices
For i = 1 To p
indices(i) = i
Next i
Dim temp1() As Long 'used to hold the values
ReDim temp1(1 To p)
Dim upperLimits() As Long
ReDim upperLimits(1 To p)
'set the upperlimits for each of the indices
'for example, indices(p) = n
For i = 1 To p
upperLimits(i) = n - p + i
Next i
Dim z As Long
x = p
For z = 1 To NumCombo
'===================
'create array containing the numbers based on the indices
For i = 1 To p
temp1(i) = numbers(indices(i))
Next i
'===================
'Print out the combination
addNumbersToView Combinations, temp1
'=======================
x = p
Do While x >= 1
If x = p And indices(x) <> upperLimits(x) Then
indices(x) = indices(x) + 1
Exit Do
End If
If x < p And indices(x) <> upperLimits(x) Then
indices(x) = indices(x) + 1
For y = x + 1 To p
indices

= indices(x) + (y - x)
Next y
Exit Do
End If
x = x - 1
Loop
'=====================
'
Next z
'Wend 'outer loop to loop through each of the different combinations
'========================
End Sub
'=======================
Public Function numCombinations(n As Long, p As Long) As Long
Dim temp As Long
'make sure that n is greater then p
If n < p Then
MsgBox "n is smaller the p in numCombinations", vbExclamation, "Error"
Exit Function
End If
temp = factorial(CLng

) / (factorial(CLng(p)) * factorial(CLng(n - p)))
numCombinations = temp
End Function
'=================================
Public Function factorial(n As Long) As Long
Dim i As Long
Dim temp As Long
temp = 1
For i = 1 To n
temp = temp * i
Next i
factorial = temp
End Function
'=====================================
'create headers in a listview
Public Sub CreateHeader(lstView As ListView, p As Long)
Dim hdrNumber() As String
Dim i As Long
ReDim hdrNumber(1 To p)
For i = 1 To p
hdrNumber(i) = CStr(i)
Next i
'add the columns
For i = 1 To p
lstView.ColumnHeaders.Add , , hdrNumber(i), 500
Next i
End Sub
'====================================
Public Sub addNumbersToView(lsvView As ListView, numbers() As Long)
Dim itmx As ListItem
Dim i As Long
Dim upper As Long
Dim lower As Long
upper = UBound(numbers)
lower = 1
Set itmx = lsvView.ListItems.Add(, , numbers(lower))
'set the subitems
For i = lower To upper - 1
itmx.SubItems(i) = CStr(numbers(i + 1))
Next i
End Sub
'====================================
Basically, all you have to do is put a listview control on a form along with a label, and when the form loads, pass an array of integers with a p value and the name of the listview control and the label, it will print out the combinations of numbers. I am sure with modifications it would do a better job. Besides if I see that the numbers I want to use get too large, then I will enter some error checking.
Troy Williams B.Eng.
fenris@hotmail.com