Post by AEOMCiao Bruno,
l'indirizzo è falso altrimenti chi mi salva dallo spam.
puoi postare il codice qui ?
ciao, AEOM
OK, eccolo di seguito.
La chiamata la fai con:
MyArray(1) = 10
MyArray(2) = 20
MyArray(3) = 30
MyArray.............
Comb MyArray, 2 | 3 | 4 | 5
Se trovi qualche bug avvisami.
Ciao
Bruno
Public Sub Comb(ArrayElementi(), ClasseCombinazione As Integer)
' ArrayElementi contiene gli elementi da combinare -- Numeri, Stringhe, etc.
' ClasseCombinazione = 2 ---> Ambo
' ClasseCombinazione = 3 ---> Terno
' ClasseCombinazione = 4 ---> Quaterna
' ClasseCombinazione = 5 ---> Cinquina
Dim i As Integer, j As Integer, k As Integer, l As Integer, p As Integer
Dim NumComb As Long, n As Integer, collComb As New Collection
n = UBound(ArrayElementi)
NumComb = 0
Select Case ClasseCombinazione
Case 2
GoSub Ambo
Case 3
GoSub Terno
Case 4
GoSub Quaterna
Case 5
GoSub Cinquina
Case Else
MsgBox "Sono ammessi:" & vbCrLf & vbLf & _
"2 ---> Ambo" & vbCrLf & _
"3 ---> Terno" & vbCrLf & _
"4 ---> Quaterna" & vbCrLf & _
"5 ---> Cinquina"
Exit Sub
End Select
For i = 1 To collComb.Count
Debug.Print i, collComb.Item(i)
Next i
'----------------------------------------
Exit Sub
'----------------------------------------
Ambo:
'----
For i = 1 To n - ClasseCombinazione + 1
For j = i + 1 To n
NumComb = NumComb + 1
collComb.Add ArrayElementi(i) & Space(2) & ArrayElementi(j)
Next j
Next i
Return
Terno:
'-----
For i = 1 To n - ClasseCombinazione + 1
For j = i + 1 To n - 1
For k = j + 1 To n
NumComb = NumComb + 1
collComb.Add ArrayElementi(i) & Space(2) & ArrayElementi(j) & _
Space(2) & ArrayElementi(k)
Next k
Next j
Next i
Return
Quaterna:
'--------
For i = 1 To n - ClasseCombinazione + 1
For j = i + 1 To n - 2
For k = j + 1 To n - 1
For l = k + 1 To n
NumComb = NumComb + 1
collComb.Add ArrayElementi(i) & Space(2) & ArrayElementi(j)
& _
Space(2) & ArrayElementi(k) & Space(2) & ArrayElementi(l)
Next l
Next k
Next j
Next i
Return
Cinquina:
'--------
For i = 1 To n - ClasseCombinazione + 1
For j = i + 1 To n - 3
For k = j + 1 To n - 2
For l = k + 1 To n - 1
For p = l + 1 To n
NumComb = NumComb + 1
collComb.Add ArrayElementi(i) & Space(2) &
ArrayElementi(j) & Space(2) & _
ArrayElementi(k) & Space(2) & ArrayElementi(l) &
Space(2) & ArrayElementi(p)
Next p
Next l
Next k
Next j
Next i
Return
End Sub