What is the BEST way to increment a letter string... ONLY LETTERS, no numbers or special characters...
A increments to B
B -> C
...
Z -> AA
AA -> AB
...
AZ -> BA
...
and so on...
the only way I know how is going through each letter in the string using the ASC(x) to eval each character from right to left, and short circuit the loop if A single letter can be changed...
like this...
Any ideas? Sometimes... the BASIC things in life are the best...
or at least the most fun ;-)
-Josh Stribling
A increments to B
B -> C
...
Z -> AA
AA -> AB
...
AZ -> BA
...
and so on...
the only way I know how is going through each letter in the string using the ASC(x) to eval each character from right to left, and short circuit the loop if A single letter can be changed...
like this...
Code:
myRev = "A"
mvRev = Revise(myRev)
Function Revise(Rev As String)
Dim I As Integer, M As Integer, Temp As String, Temp2 As String
Dim A As Integer, Z As Integer
A = Asc("A"): Z = Asc("Z")
Temp = UCase(Rev)
For I = Len(Rev) To 1 Step -1
M = Asc(Mid(Temp, I, 1))
If M >= A And M <= Z Then
If M + 1 > Z Then
Temp2 = "A"
If I < Len(Temp) Then Temp2 = Temp2 & Right(Temp2, Len(Temp) - (I))
If I > 1 Then
Temp2 = Left(Temp, I - 1) & Temp2
Else
Temp = "A" & Temp2
Exit For
End If
Temp = Temp2
Else
Temp2 = ""
If I > 1 Then Temp2 = Left(Temp, I - 1)
Temp2 = Temp2 & Chr(M + 1)
If I < Len(Temp) Then Temp2 = Temp2 & Right(Temp, Len(Temp) - I)
Temp = Temp2
Exit For
End If
Else
Exit For
End If
Next
Revise = Temp
End Function
or at least the most fun ;-)
-Josh Stribling