Imports System.Text
Module Module1
Function IsRestOfStr(ByVal Tag As String, ByVal Position As Integer) As Boolean
' Checks to see if the rest of the string is all Z's
IsRestOfStr = False
Dim StrTag As New StringBuilder("")
StrTag.Append("Z"c, Tag.Length - (Position + 1))
IsRestOfStr = (StrTag.ToString = Tag.Substring(Position + 1))
End Function
Sub ChangeLetter(ByRef Tag As String, ByVal Position As Integer)
' Changes the letter at the specified position
' Moves to the next letter in the sequence, if it is Z then resets it to A
Dim SubStr As String
SubStr = Tag.Substring(Position, 1)
If SubStr = "Z" Then
SubStr = "A"
Else
SubStr = Chr(Asc(SubStr) + 1)
End If
Tag = Tag.Remove(Position, 1)
Tag = Tag.Insert(Position, SubStr)
End Sub
Sub NextLetter(ByRef Tag As String, ByVal Position As Integer)
' Checks the letter at the specified position
Dim SubStr As String
If Position = (Tag.Length - 1) Then
' If this is the last letter in the string then set to the next letter
' If it is Z then set to A
ChangeLetter(Tag, Position)
Else
' Check to see if the rest of the string is all Z's
If IsRestOfStr(Tag, Position) Then
' If they are then increment this letter
ChangeLetter(Tag, Position)
End If
End If
End Sub
Sub NextTag(ByRef Tag As String)
' Moves the letters in the Tag String to the next in sequence
' Runs through the entire string.
Dim Position As Integer
For Position = 0 To (Tag.Length - 1)
NextLetter(Tag, Position)
Next ' Position = 0 to (Tag.length-1)
End Sub ' NextTag
Sub Main()
' testing the code
Dim StartTag As String = "AAA"
Dim Idx As Integer
For Idx = 1 To 680
Console.WriteLine(Idx & " " & StartTag)
NextTag(StartTag)
Next ' Idx
Console.WriteLine("Press Enter to Continue")
Console.ReadLine()
End Sub
End Module