Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionMais voici mon code. Si j'ai choisi la rubrique "débutant", ce n'est pas pour rien....
Après recherche, j'ai trouvé la réponse
Dim mes_fruits mes_fruits = Array("pomme", "poire", "orange", "banane", "fraise") Dim nb As Integer, i As Integer, debut As Integer, fin As Integer, j As Integer, Ah As String, Oh As String, Hou As Integer mes_cocktails.Clear mes_cocktails.Visible = False nb = UBound(mes_fruits) + 1 For i = 1 To nb mes_cocktails.AddItem i Next debut = 0 fin = mes_cocktails.ListCount - 1 Do For i = debut To fin Ah = Val(mes_cocktails.List(i)) If Ah = 0 Then Exit Do Oh = mes_cocktails.List(i) Hou = InStr(Oh, "-") If Hou Then mes_cocktails.List(i) = mes_fruits(Val(Oh) - 1) & Mid(Oh, Hou) Else mes_cocktails.List(i) = mes_fruits(Val(Oh) - 1) End If For j = Ah + 1 To nb mes_cocktails.AddItem j & "-" & mes_cocktails.List(i) Next Next debut = fin + 1 fin = mes_cocktails.ListCount Loop mes_cocktails.Visible = True MsgBox mes_cocktails.ListCount & " coquetels (restons français)"
On pourrait en inventer d'autres
Dim i As Integer,j As Integer,k As Integer, _ m As Integer,n As Integer Dim T1(2) As String,T2(2) As String,T3(2) As String, _ T4(2) As String,T5(2) As String Dim c As Integer Dim COMBI() As String T1(1)="Pomme-":T1(2)="" T2(1)="Poire-":T2(2)="" T3(1)="Orange-":T3(2)="" T4(1)="Banane-":T4(2)="" T5(1)="Fraise":T5(2)="" For I=1 To 2 For j=1 To 2 For k=1 To 2 For m=1 To 2 For n=1 To 2 c=c+1 Redim Preserve COMBI(c) COMBI(c)=T1(i) & T2(j) & _ T3(k) & T4(m) & T5(n) Next Next Next Next Next
Const Element = 5 Private listmots(Element - 1) As String Private combinaisons() As String Private Sub MakeCombinaison() Dim place As Integer Dim strcomb As String Dim counter As Long Dim checknum As Integer counter = 0 For number = 1 To 2 ^ (Element) - 1 strcomb = "" 'on convertit number en binaire et on verifie si le digit obtenu = 1 et on prend ' la valeur de listmots indexe par place place = 0 checknum = number While checknum > 0 If checknum Mod 2 = 1 Then strcomb = strcomb & listmots(place) & " " End If place = place + 1 checknum = checknum \ 2 Wend ReDim Preserve combinaisons(counter) combinaisons(counter) = strcomb counter = counter + 1 Next number End Sub Private Sub Form_Load() listmots(0) = "pomme" listmots(1) = "poire" listmots(2) = "banane" listmots(3) = "orange" listmots(4) = "fraise" MakeCombinaison End Sub