Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function IncrementTextString(txt As String) As String
- 'taken from http://www.freevbcode.com/ShowCode.asp?ID=2071
- 'enhanced to take in numbers also
- Dim L As Integer, i As Integer, c As Integer
- Dim S As String
- S = txt
- L = Len(S)
- For i = L To 1 Step -1 'go thru the string, right to left
- c = Asc(Mid(S, i, 1)) 'ASCII code of the i-th character
- Select Case c
- Case 65 To 89, 97 To 121, 48 To 56 'A-Y or a-y or 0-8
- S = Left(S, i - 1) & Chr(c + 1) & Mid(S, i + 1)
- Exit For
- Case 90 'Z
- S = Left(S, i - 1) & "A" & Mid(S, i + 1)
- Case 122 'z
- S = Left(S, i - 1) & "a" & Mid(S, i + 1)
- Case 57 '0
- S = Left(S, i - 1) & "0" & Mid(S, i + 1)
- End Select
- 'in the last two cases, we need to continue the loop:
- Next i
- If i = 0 Then
- IncrementTextString = String(L + 1, 65) 'grow the string
- Else
- IncrementTextString = S
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement