VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Recursive permutations

by Jolyon Bloomfield (9 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

Takes in a string and spits out all possible permutations of the inputted characters using a simple recursive routine. Good recursive example.

Assumes
Put the lot onto a form, put a command button "command1" on the form, put a textbox "text1" on the form, and run.

Rate Recursive permutations

Private Sub Command1_Click()
Open "C:\windows\desktop\words.txt" For Output As #1
Recurse Text1.Text, ""   ' string so permutate is text1.text
Close #1
Shell "C:\windows\notepad.exe C:\windows\desktop\words.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

Download this snippet    Add to My Saved Code

Recursive permutations Comments

No comments have been posted about Recursive permutations. Why not be the first to post a comment about Recursive permutations.

Post your comment

Subject:
Message:
0/1000 characters