VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Create all combinations of letters of a certain length


Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Create all possible combinations of letters with this little recursion function...

Inputs
The maximum size of the words to create.
Code Returns
All combinations of letters of that size.
API Declarations
'If you don't feel like downloading the zip
'file... here's the sub to create the words:
Public Sub Letters(max As Integer)
'Local variables
Dim CycleLetters As Integer
'Static local variables
Static level As Integer
Static strBase As String
'Increase level
level = level + 1
'Make sure it stays within its max
If level > max Then
level = level - 1
Exit Sub
End If
For CycleLetters = 1 To 26
strBase = strBase + Chr(CycleLetters + 96)
If Len(strBase) = max Then
' Here is where you can handle the word
' i.e. - add to a listbox
' Use the variable strBase
End If

'Recurse to get next letter
Letters max
strBase = Mid(strBase, 1, Len(strBase) - 1)
Next
level = level - 1
End Sub

Rate Create all combinations of letters of a certain length

Upload

Download this snippet    Add to My Saved Code

Create all combinations of letters of a certain length Comments

No comments have been posted about Create all combinations of letters of a certain length. Why not be the first to post a comment about Create all combinations of letters of a certain length.

Post your comment

Subject:
Message:
0/1000 characters