Convert letters to numbers

 

This code will convert letters to numbers, you can see what phone number your name would make, of just to have a personalized phone number.

The first function translates letters into numbers; the second function applies the translation to an entire phone number. The method works with phone numbers that have different formats (for example, "800-555-GIGO" or "800555GIGO") as well as with phone numbers that have different lengths (for example, "555-GIGO" or "011-01-704-555-GIGO").

Start a new project add a text box, lable and a commnad button on the form. Add a standard module and type the following line in the Declarations section:
------------------------------------- Add to Module -------------------------------------

Option Explicit

' Translates a letter to a digit.
Function letToNum(ByVal C As String) As String
C = UCase(C)
Select Case C
Case "A" To "P"
letToNum = Chr$((Asc(C) + 1) \ 3 + 28)
Case "R" To "Y"
letToNum = Chr$(Asc(C) \ 3 + 28)
Case "Q", "Z"
letToNum = "0"
Case Else
letToNum = C
End Select
End Function


' Applies the translated digit to a phone number.
Function LettersToNumber(ByVal PhoneNo As Variant) As Variant
Dim I As Integer
If VarType(PhoneNo) = 8 Then ' A string.
For I = 1 To Len(PhoneNo)
Mid(PhoneNo, I, 1) = letToNum(Mid(PhoneNo, I, 1))
Next I
End If
LettersToNumber = PhoneNo
Label1 = PhoneNo
End Function

'----------------------------------- Add to Form -------------------------------

Private Sub Command1_Click()
LettersToNumber Text1

End Sub


Now type pro-gra-mmer in the text box and click on the command button and the number below will be displayed.


776-472-6637