Advancing to next letter, programatically

T

TRM

I have records which are tracking the version of a document using the
alphabet for the version number. Originally the request was for the version
to go up to "G", but they have now found they would like the version to be
"endless". So, I'm trying to figure out how to go from "A" to "B" (and "AA"
to "BB" - etc.) withough using 2 or 3 (see below) hardcoded lines per
letter/round.

I am currently testing the idea of "A" thru "A9" for each letter (with
'minimal' ?? coding), but I'm not sure yet if the customer will be satisfied
with that option.

Here is a snippet of what I currently have in use:
' Case "A"
' strVer = "B"
' Case "B"
' strVer = "C"
' Case "C"
' strVer = "D"
' Case "D"
' strVer = "E"
' Case "E"
' strVer = "F"
' Case "F"
' strVer = "G"
' End Select
 
K

Karl E. Peterson

TRM said:
I have records which are tracking the version of a document using the
alphabet for the version number. Originally the request was for the
version to go up to "G", but they have now found they would like the
version to be "endless". So, I'm trying to figure out how to go from
"A" to "B" (and "AA" to "BB" - etc.) withough using 2 or 3 (see
below) hardcoded lines per letter/round.

To use the same scheme as, say, Excel, you could do something like this:

Public Function Letters(ByVal Value As Long) As String
Dim Digit As Long
Dim sReturn As String
Const AlphaBase As Long = 64 'Asc("A")-1

Do While Value > 26
Digit = Value \ 26
sReturn = sReturn & Chr$(AlphaBase + Digit)
Value = Value - (Digit * 26)
Loop

' Return results
Letters = sReturn & Chr$(AlphaBase + Value)
End Function

This is basically Base26, using the "digits" A-Z. So, for version 256
(coincidentally, and for easy verification, the last column in Excel <g>),
you could ask for:

Letters(256)

And get back "IV".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top