Recursive permutations
Takes in a string and spits out all possible permutations of the inputted characters using a simple recursive routine. Good recursive example.
Original Author: Jolyon Bloomfield
Assumptions
Put the lot onto a form, put a command button "command1" on the form, put a textbox "text1" on the form, and run.
Code
Private Sub Command1_Click()
Open "C:windowsdesktopwords.txt" For Output As #1
Recurse Text1.Text, "" ' string so permutate is text1.text
Close #1
Shell "C:windows
otepad.exe C:windowsdesktopwords.txt", vbNormalFocus
End Sub
Private Sub Recurse(ByVal Letters As String, ByVal Built As String)
Dim I As Integer
If Len(Letters) = 1 Then
Print #1, Built & Letters
Exit Sub
End If
For I = 1 To Len(Letters)
Recurse Mid(Letters, 1, I - 1) & Mid(Letters, I + 1), Built & Mid(Letters, I, 1)
Next I
End Sub
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.