VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Create all combinations of letters of a certain length

Miscellaneous   Visual Basic 3.0   Beginner   Wed 3rd February 2021

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

Inputs
The maximum size of the words to create.

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 (3(3 Vote))
Create all combinations of letters of a certain length.bas

Create all combinations of letters of a certain length Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters