Link to home
Start Free TrialLog in
Avatar of KentKirimli
KentKirimli

asked on

Routine to Create a New Revision

Hello Experts,

I'm coding in VB6.

Does anyone know of a function where I can create a new sequential Alpha revision/version after passing a current revision (imagine a document control system where document revisions are roled upon checking in a new doc version.) For example, say the current revision of a document is 'B' and the function would have to return the next revision which would be 'C'. That part is simple enogh. (I expect the ASC/CHR functions would be used as part of this function).

However, the tricky part comes in being able to handle when the current Rev is 'Z'. it needs to return the next revision as 'AA'. Then, subsequent revisions would be 'AB', 'AC', 'AD' ...etc. Then, once again on 'AZ, we need to return 'BA', 'BB', 'BC' etc. There should be no practical limit to the uppermost revision (e.g. a revision may exists as 'AAA' ). This will no doubt call for some type of recursion.

I've assigned a high point value to reflect the urgency of the request, which is high.

Thanks much in advance.
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Hi KentKirimli,

I have used this method a couple of years ago for Excel columns:

' *****************************************************************
' ***
' *** Retourne la colonne suivante dans Excel
' *** Eric Moreau 1998.09.14
' ***
' *****************************************************************
Public Function NextNomColumn(ByVal pstrCol As String) As String
Dim strFirst As String
Dim strLast As String

    If Len(pstrCol) > 1 Then strFirst = Left$(pstrCol, 1)
    strLast = Right$(pstrCol, 1)
   
    If strLast = "Z" Then
        If strFirst = "" Then
            strFirst = "A"
        Else
            strFirst = Chr$(Asc(strFirst) + 1)
        End If
        strLast = "A"
    Else
        strLast = Chr$(Asc(strLast) + 1)
    End If
   
    NextNomColumn = strFirst & strLast
End Function

Cheers!
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KentKirimli
KentKirimli

ASKER

Thanks Idle Mind, thats exactly what I was looking for.