Module Module1
'First of all I would like to say that the reason I use global
'variables in all of my subs Is that I have been seeing some memory
'problems.
Dim abcStr As String = "" 'the string we change (generate)
Dim lastabcStr As String = "" 'the last string we want to come to
Const minChar As Char = "a" 'the smaller letter
Const maxChar As Char = "c" 'the bigger letter
Dim len As Integer = 10 'the max length of the string we want to generate
Dim i As Integer 'this is just a variable for loops
Dim notFound As Boolean 'another varilable for while loops
''' <summary>
''' the sub putCharAtPos insert a char instead of an existing char
''' it was created since the chars property of the string is readonly
''' </summary>
''' <param name="s">the string variable</param>
''' <param name="pos">the position of the char</param>
''' <param name="c">the new char to insert</param>
''' <remarks></remarks>
Sub putCharAtPos(ByRef s As String, ByVal pos As Integer, ByVal c As Char)
s = Left(s, pos) + c.ToString + Right(s, s.Length - pos - 1)
End Sub
''' <summary>
''' the sub is for generating the next combination of chars
''' and showing it...
''' </summary>
''' <remarks>recursive</remarks>
Sub nextAbc()
If abcStr.Length < len Then ' if the number of letters is not the last one
notFound = True ' will tell us if we can steel go on with this number of letters
i = 0 ' will point to to the char we want to check
While (i < abcStr.Length) And (notFound) ' while we didn't find a letter that can't be Increased
If abcStr.Chars(i) = maxChar Then ' if this letter can't be Increased
i += 1 ' I will point to the next letter
Else ' if this letter can be Increased
notFound = False
End If ' abcStr.Chars(i) = maxChar
End While ' (i < abcStr.Length) And (notFound)
If notFound Then ' if this hole string can't be Increased
WriteLine(abcStr) ' we show the string
Beep(3000, 750) ' show when adding a letter
i = abcStr.Length '
abcStr = "" ' we generate a string that will be lengthed one char more than the last one
For i = 0 To i ' and all chars will the smaller char.
abcStr += minChar.ToString
Next ' for i =0 to i (the length of abcStr)
End If ' notFound
End If ' abcStr.Length < len
If abcStr < Left(lastabcStr, abcStr.Length) Then ' if the string is not the last one
WriteLine(abcStr) ' show the string
i = abcStr.Length - 1 ' points to the last letter
notFound = True ' the letter can be Increased
While (i > 0) And (notFound)
If abcStr.Chars(i) >= maxChar Then
putCharAtPos(abcStr, i, minChar)
i -= 1
Else
notFound = False
End If
End While
putCharAtPos(abcStr, i, Convert.ToChar(Convert.ToByte(abcStr.Chars(i)) + 1))
nextAbc()
Else
Write(lastabcStr)
End If
End Sub
Sub Main()
abcStr = minChar
For i As Integer = 1 To len
lastabcStr += maxChar
Next
nextAbc()
Beep(100, 2000)
End Sub
End Module