VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converts strings to its numbered representation in the alphabet, E.G AB to 12, CD to 34 e.t.c

by Raza Hasnain (2 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 28th April 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converts strings to its numbered representation in the alphabet, E.G AB to 12, CD to 34 e.t.c

Rate Converts strings to its numbered representation in the alphabet, E.G AB to 12, CD to 34 e.t.c



'Use this Numeriser - procedure to pass in a bunch of characters as a string, it will then return a numeric repersentation
'of the alphabet.



Public Function Numeriser(BunchOfCharacters As String)

        On Error GoTo err_
        
        Dim IntStrlen, n As Integer
        Dim CodedVal, Sts As String
        'Declare array
        Dim ArrayA()
        
        If IsNull(BunchOfCharacters) = True Then
                Exit Function
        End If
        'Get number of characters in string
        IntStrlen = Len(BunchOfCharacters)
        'Loop By the number of characters in the Passed STRING
             
        'Set the lenghth of the array to the number of characters in the string
        ReDim ArrayA(IntStrlen)
        'Loop by the number of characters in the string
        For n = 1 To IntStrlen

                'Get each character in the string by starting at n position and grabbing the first characater
                Sts = Sts & ConvNum(Mid$(BunchOfCharacters, n, 1))
                Debug.Print Sts
                'Return value
                Numeriser = Sts
                
        Next
        Exit Function
        
err_:
        MsgBox Err.Description
        Err.Clear
        
        
End Function

Private Function ConvNum(CharX As Variant)
        
        On Error GoTo err_
        
        
        Dim strArray
        Dim Counterx As Integer
        Dim strItem As Variant
        Dim intEquivPos As Integer
        Dim CharacterX As String
        'Clear String vairable
        CharacterX = Empty
        'Convert all Characters to upper case
        CharacterX = UCase(CharX)
        
        'You can more character types in this array
        strArray = 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", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0")
        'loop through the array
        For Each strItem In strArray
                'compare characters
                If CharacterX = strItem Then
                        intEquivPos = Counterx + 1
                      
                End If
             
                Counterx = Counterx + 1
                
                 Next
        
 
        
        ConvNum = intEquivPos
        Exit Function
        
err_:
        MsgBox Err.Description
        Err.Clear
        
End Function

Download this snippet    Add to My Saved Code

Converts strings to its numbered representation in the alphabet, E.G AB to 12, CD to 34 e.t.c Comments

No comments have been posted about Converts strings to its numbered representation in the alphabet, E.G AB to 12, CD to 34 e.t.c. Why not be the first to post a comment about Converts strings to its numbered representation in the alphabet, E.G AB to 12, CD to 34 e.t.c.

Post your comment

Subject:
Message:
0/1000 characters