UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> IncrementDomain    
CODE
' Code courtesy of UtterAccess Wiki
' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary
' Original submission by Walter Niesz
' July 26, 2010
'
' You are free to use this code in any application,
' provided the copyright notice is left unchanged.

' DESCRIPTION
' This function increments any given string by 1 over a set domain.
' It can be used when a custom counting scheme is required, or a base(x) number is needed
' Certain pre-defined domains are included and can be selected via an optional argument


Public Function IncrementDomain(GivenString As String, _
                                Optional PreSetDomain As String, _
                                Optional GivenDomain As String, _
                                Optional GivenRolloverCharacter As String) As String
 
   Dim Domain As String
   Dim Rollovercharacter As String
   Dim CurrentCharacter As String
   Dim i As Long
     
   Select Case PreSetDomain
       Case "Binary"
           Domain = "01"
           Rollovercharacter = "1"
       Case "Decimal"
           Domain = "0123456789"
           Rollovercharacter = "1"
       Case "HexaDecimal"
           Domain = "0123456789ABCDEF"
           Rollovercharacter = "1"
       Case "AlphabeticUpper"
           Domain = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
           Rollovercharacter = "A"
       Case "AlphabeticLower"
           Domain = "abcdefghijklmnopqrstuvwxyz"
           Rollovercharacter = "a"
       Case "AlphabeticUpperAndLower"
           Domain = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
           Rollovercharacter = "a"
       Case "AlphaNumericUpper"
           Domain = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
           Rollovercharacter = "1"
       Case "AlphaNumericUpperAndLower"
           Domain = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
           Rollovercharacter = "1"
       Case Else
           If GivenDomain = "" Then
               Domain = "0123ABC"                  ' <=== assign default or custom domain here
           Else
               Domain = GivenDomain
           End If
           If GivenRolloverCharacter = "" Then
               Rollovercharacter = "1"             ' <=== assign default or custom rollovercharacter here
           Else
               Rollovercharacter = GivenRolloverCharacter
           End If
    End Select
     
   For i = Len(GivenString) To 1 Step -1
       CurrentCharacter = Mid(GivenString, i, 1)
       If StrComp(CurrentCharacter, Right(Domain, 1), vbBinaryCompare) = 0 Then
           IncrementDomain = Left(Domain, 1) & IncrementDomain
       Else
           IncrementDomain = Mid(Domain, InStr(Domain, CurrentCharacter) + 1, 1) + IncrementDomain
           IncrementDomain = Left(GivenString, i - 1) & IncrementDomain
           Exit Function
       End If
   Next i
   
   IncrementDomain = Rollovercharacter & IncrementDomain
   
End Function


Creative Commons License
IncrementDomain by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 3,039 times.  This page was last modified 09:37, 6 April 2011 by Jack Leach. Contributions by Walter Niesz  Disclaimers