Text1 Enter the total number of numbers; Text2 Enter the number of numbers of each group; app.path & "/1.txt" is used to see the output result; Label1 is used to display the number of groups; Command1 is the execution button. This is a universal code for exhaustion combined results.
Option expedition
Private mlngallnumcount as long, mlnggetnumcount as ring
Private MblncancelProc as Boolean, MLNGCURRESULTCOUNT AS Long
Private maastroneResult () AS String
Private mlngfileno as long
Private Sub ListNum (Byval Start As Long, BYVAL Level As Long)
DIM I as long
IF MBLNCANCALPROC THEN EXIT SUB
For i = start to mlngallnumcount - MLNGGETNUMCOUNT Level
MastroneResult (Level) = i
If level ListNum i 1, Level 1 'has not, recursive, this is the core of this process, very simple Else Print # mlngfileno, join (mastroneResult, vbtab) 'recursive to the deepest layer, you can output it. mlngcurresultcount = mlngcurResultcount 1 IF MLNGCURRESULTCOUNT MOD & H2000 & = 0 THEN Label1.caption = mlngcurresultcount 'shows how many group numbers do actually Doevents END IF END IF NEXT End Sub Private submmand1_click () Dim t as single, i as long If Command1.caption = "Processing" THEN MLNGALLNUMCOUNT = text1.text 'Number of numbers MLNGGETNUMCOUNT = TEXT2.TEXT 'Number of numbers taken each group I = zhuhe (mlngallnumcount, mlnggetnumcount) IF i = 0 THEN Msgbox "There are too many results, please don't try it!" EXIT SUB END IF Label2.caption = i T = Timer MBLNCANCELPROC = FALSE Command1.caption = "Stop" MLNGCURRESULTCOUNT = 0 'has generated total number of combinations Redim MastroneResult (1 to mlnggetnumcount) mlngfileno = freefile Open app.path & "/1.txt" for output as #mlngfileno ListNum 1, 1 Close # mlngfileno Label1.caption = mlngcurresultcount Command1.caption = "Processing" Me.caption = Timer - Telse MBLNCANCELPROC = TRUE END IF End Sub PRIVATE FUNCTION ZHUHE (Allnum as long, getnum as long) AS Long 'The process of calculating the total number of combinations, to prevent overflow, and do special design 'As long as the total number is 2 billion, it will not overflow. 'Too big number is unlikely to complete the exhaustion, this procedure is not trying. 'The upper limit of near overflow: 65536 take 2,2345 take 3,477 take 4, 193 take 5, 110 take 6 '75 takes 7, 58 take 8, 49 take 9, 40 takes 10, 39 take 11, 37 take 12, 35 take 13, 34 take 15, 33 take 16, etc. DIM I As Long, J AS Long, Colget As Collection DIM M As Long, N As Long, Num1 As Long, Num2 As Long ON Error Goto Fail Num1 = 1 SET Colget = New Collection For i = getnum to 2 step -1 COLGET.ADD I NEXT For i = allnum to allnum - getnum 1 step -1 m = colget.count IF m> 0 THEN N = m For j = 1 to m IF j> n Then EXIT for IF Num1 Mod Colget (j) = 0 THEN Num1 = Num1 / COLGET (j) Colget.remove J n = n - 1 J = J - 1 END IF NEXT END IF Num2 = i m = colget.count IF m> 0 THEN N = m For j = 1 to m IF j> n Then EXIT for IF Num2 Mod Colget (j) = 0 THEN Num2 = Num2 / COLGET (j) Colget.remove J n = n - 1 J = J - 1 END IF NEXT END IF Num1 = Num1 * Num2 'two multipliers in the molecule eliminates the multiplication of the denominator, but the overflow of the intermediate process NEXT Zhuhe = Num1 EXIT FUNCTION Fail: END FUNCTION Private sub flow_load () Command1.caption = "Processing" End Sub Private Sub Form_Unload (Cancel AS Integer) MBLNCANCELPROC = TRUE End Sub