Development‎ > ‎VBScript‎ > ‎

Letter class

Following code allows for generating subsequent letters as thay go in the alphabet.

'*********************************************************************************
'* Class name: LetterClass
'*
'* property currentLetter
'*
'* method setFirstLetter
'* method nextLetter
'* method previousLetter
'* method toInteger
'*
'*********************************************************************************
Class LetterClass
    Private aParamList
    Private last_i, last_ii

    Private iInit
        Private iiInit
 
    Sub setFirstLetter(CustomIInit, CustomIIInit)
        last_i = CustomIInit
        last_ii = CustomIIInit
    End Sub

 
    Private Sub class_Initialize()
        iInit = 0
        iiInit = 1
 

        aParamList = array("", "A" ,"B" ,"C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S", "T", "U", "V", "W", "X", "Y", "Z")
        last_i = iInit
        last_ii = iiInit
    End Sub
 
    Property Get currentLetter
        currentLetter = aParamList(last_i) & aParamList(last_ii)
    End Property
 
    Function nextLetter          
        If last_ii = UBound(aParamList) Then
            last_ii = iiInit
            last_i = last_i + 1
        Else
            last_ii = last_ii + 1
        End If

 
        If (last_i = UBound(aParamList)+1) And (last_ii = iiInit) Then
            last_i = 0 'iInit
            last_ii = 1 'iiInit
        End If
         
                nextLetter = aParamList(last_i) & aParamList(last_ii)
        End Function
       
    Function previousLetter
        If last_ii = iiInit Then
            last_ii = UBound(aParamList)
            last_i = last_i - 1
        Else
            last_ii = last_ii - 1
        End If
    

        If (last_i = iInit)  And (last_ii = iiInit) Then
            last_i = UBound(aParamList)
            last_ii = UBound(aParamList)
        End If     

        previousLetter = aParamList(last_i) & aParamList(last_ii)
    End Function     

       

    Function toInteger
        toInteger = (last_i * UBound(aParamList) + last_ii) - (iInit * UBound(aParamList) + iiInit)
    End Function
       
End Class


Here is an example on how this class could be used:

'Declare the variable and create new instance of the LetterClass
Dim oLetter : Set oLetter = new LetterClass

'Display the current letter
MsgBox oLetter.currentLette 'Call returns: A

'Advance to the next letter and return the new letter from the function
MsgBox oLetter.nextLetter 'Call returns: B

'Advance to the previouse letter and return the new letter from the function
MsgBox oLetter.previousLetter 'Call returns: A

'Display the current letter
MsgBox oLetter.currentLette 'Call returns: A

Comments