Here is some code I got a while ago, to tell me all the different combinations of 1-9, then save to a txt file.
It all works fine, but I don't really understand it, and now I need just numbers 1-6 combinations.Code:Option Explicit 'Must Declare all variables, I think that it is good practice Option Base 1 'For simplicity, make array index start at 1 To n Sub Perm(A() As String * 1, m, n As Integer) Dim i As Integer Dim Temp As String * 1 If m = 1 Then PrintPerm A, n 'Print out the permutations Else For i = 1 To m Temp = A(i) A(i) = A(m) 'Exchange A(i) and A(m), could have made a Sub To Do this A(m) = Temp Perm A, m - 1, n 'Recursive Function call Temp = A(m) A(m) = A(i) 'Exchange A(m) and A(i) A(i) = Temp Next i End If End Sub Private Sub Command1_Click() Dim strArray(9) As String * 1 Dim x As Long 'create array of values 1..9 For x = 1 To 9 strArray(x) = Trim(CStr(x)) Next x Perm strArray(), 6, 6 'Of course you could use variables For this End Sub Public Sub PrintPerm(A() As String * 1, n As Integer) Dim i As Integer Dim strVar As String For i = 1 To n strVar = strVar & (A(i)) Next i Dim combspath combspath = "C:\permutations.txt" Dim filenum As Integer filenum = FreeFile Open combspath For Append As #filenum Print #filenum, strVar Close #filenum Text1.Text = strVar End Sub
Can anyone tell me how to modify so it does that?
Thanks




Reply With Quote