Generate all combination from some number (takes for classes 8)

B

barbun

Hi from italy !
so sorry for my bad english :)

I hope to be clear :

***This is for a play similar your Lotto or Bingo, where for win you have to
forecast 8 number on 32 ***


I have a table "Pronostico" with only field "NR" where I put some MY numer
from 1 to 32
(sometimes i put in 23 number, sometimes i pun in 20 number ecc ecc
example of number so are :
2
4
5
7
9
10
11
13
14
15
18
ecc ecc

I simply want generate all possible combination for all number i put in
table "Pronostico" TAKES FOR CLASSES 8
so for the number above some, combination generate will be :

2 4 5 7 9 10 11 13
2 4 5 7 9 10 11 14
2 4 5 7 9 10 11 15
2 4 5 7 9 10 11 18
ecc ecc

I have write this code , where is write "Int(vin!Nr) To Int(vin!Nr)" , is my
last stupid tentative to generate my
all combination.....can you help me in my search ???


Public Sub test20()

Dim Num1 As Byte
Dim Num2 As Byte
Dim Num3 As Byte
Dim Num4 As Byte
Dim Num5 As Byte
Dim Num6 As Byte
Dim Num7 As Byte
Dim Num8 As Byte


DoCmd.SetWarnings False

DoCmd.RunSQL "DELETE * FROM Colonne;"

DoCmd.SetWarnings True

Set rst = CurrentDb.OpenRecordset("Colonne")
Set vin = CurrentDb.OpenRecordset("Pronostico")


For Num1 = Int(vin!Nr) To Int(vin!Nr)

For Num2 = Int(vin!Nr) To Int(vin!Nr)

If Num2 <> Num1 Then

For Num3 = Int(vin!Nr) To Int(vin!Nr)

If Num3 <> Num1 And Num3 <> Num2 Then

For Num4 = Int(vin!Nr) To Int(vin!Nr)

If Num4 <> Num1 And Num4 <> Num2 And _
Num4 <> Num3 Then

For Num5 = Int(vin!Nr) To Int(vin!Nr)

If Num5 <> Num1 And Num5 <> Num2 And _
Num5 <> Num3 And Num5 <> Num4 Then


For Num6 = Int(vin!Nr) To Int(vin!Nr)
If Num6 <> Num1 And Num6 <> Num2 And Num6 <> _
Num3 And Num6 <> Num4 And Num6 <> Num5 Then


For Num7 = Int(vin!Nr) To Int(vin!Nr)


If Num7 <> Num1 And Num7 <> Num2 And Num7 <> _
Num3 And Num7 <> Num4 And Num7 <> Num5 And Num7 <> Num6 Then

For Num8 = Int(vin!Nr) To Int(vin!Nr)

If Num8 <> Num1 And Num8 <> Num2 And Num8 <> _
Num3 And Num8 <> Num4 And Num8 <> Num5 And Num8 <> Num6 And Num8 <> Num7
Then

rst.AddNew
rst!Num1 = Num1
rst!Num2 = Num2
rst!Num3 = Num3
rst!Num4 = Num4
rst!Num5 = Num5
rst!Num6 = Num6
rst!Num6 = Num7
rst!Num6 = Num8

rst.Update
End If
Next Num8
End If
Next Num7
End If
Next Num6
End If
Next Num5
End If
Next Num4
End If
Next Num3
End If
Next Num2
Next Num1
Set rst = Nothing


End Sub
 
A

Alex Dybenko

Hi,
just some quick code
first you read Pronostico into array P(1:20)
then you make nested loops (8)
for i1=1 to 20
for i2=1 to 20
...
for i8=1 to 20
rst.AddNew
rst!Num1 = P(i1)
rst!Num2 = P(i2)
...
rst!Num8 = P(i8)
rst.update
next i8
....
next i1
 
B

barbun

Alex Dybenko said:
Hi,
just some quick code
first you read Pronostico into array P(1:20)
then you make nested loops (8)
for i1=1 to 20
for i2=1 to 20
...
for i8=1 to 20
rst.AddNew
rst!Num1 = P(i1)
rst!Num2 = P(i2)
...
rst!Num8 = P(i8)
rst.update
next i8
...

sorry i was very weak with vba :(
can you arrange this ???????
please !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


Public Sub test200()

Dim Num1 As Byte
Dim Num2 As Byte
Dim Num3 As Byte
Dim Num4 As Byte
Dim Num5 As Byte
Dim Num6 As Byte
Dim Num7 As Byte
Dim Num8 As Byte


Dim P(1, 20) As Byte

P = CurrentDb.OpenRecordset("Pronostico")




DoCmd.SetWarnings False

DoCmd.RunSQL "DELETE * FROM Colonne;"

DoCmd.SetWarnings True

Set rst = CurrentDb.OpenRecordset("Colonne")




For Num1 = 1 To 20
For Num2 = 1 To 20
If Num2 <> Num1 Then

For Num3 = 1 To 20
If Num3 <> Num1 And Num3 <> Num2 Then

For Num4 = 1 To 20
If Num4 <> Num1 And Num4 <> Num2 And _
Num4 <> Num3 Then

For Num5 = 1 To 20
If Num5 <> Num1 And Num5 <> Num2 And _
Num5 <> Num3 And Num5 <> Num4 Then


For Num6 = 1 To 20
If Num6 <> Num1 And Num6 <> Num2 And Num6 <> _
Num3 And Num6 <> Num4 And Num6 <> Num5 Then


For Num7 = 1 To 20
If Num7 <> Num1 And Num7 <> Num2 And Num7 <> _
Num3 And Num7 <> Num4 And Num7 <> Num5 And Num7 <> Num6 Then

For Num8 = 1 To 20
If Num8 <> Num1 And Num8 <> Num2 And Num8 <> _
Num3 And Num8 <> Num4 And Num8 <> Num5 And Num8 <> Num6 And Num8 <> Num7
Then

rst.AddNew
rst!Num1 = P(i1)
rst!Num2 = P(i2)
rst!Num3 = P(i3)
rst!Num4 = P(i4)
rst!Num5 = P(i5)
rst!Num6 = P(i6)
rst!Num7 = P(i7)
rst!Num8 = P(i8)

rst.Update
End If
Next Num8
End If
Next Num7
End If
Next Num6
End If
Next Num5
End If
Next Num4
End If
Next Num3
End If
Next Num2
Next Num1
Set rst = Nothing

Next i1

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top