locked
convert decimal numbers to words in vb 2008 RRS feed

  • Question

  • In short let's say i have a form with a text box and a label. I am going to insert a number for example "1365" in the text box and then in the forms label it'll output "one thousand three hundred sixty five".
    Friday, November 4, 2011 5:20 PM

Answers

  • I didn't write this, but had it tucked away in a "useful code" folder... It was designed to take numerics and output the text for check writing, so it will append things like "dollars" to the string, but you should be able to edit it to your specific needs.

    Option Strict Off
    
    Public Class NumberToWord
        Dim mNos(99) As String
    
        Public Shared Function Convert(ByVal Num As String) As String
            Return ReturnWordsFromNumber(Num)
        End Function
        Public Shared Function Convert(ByVal Num As Integer) As String
            Return ReturnWordsFromNumber(Num.ToString)
        End Function
        Public Shared Function Convert(ByVal Num As Double) As String
            Return ReturnWordsFromNumber(Num.ToString)
        End Function
        Public Shared Function Convert(ByVal Num As Decimal) As String
            Return ReturnWordsFromNumber(Num.ToString)
        End Function
        Private Shared Function ReturnWordsFromNumber(ByVal Number As String) As String
            Dim FormattedNumber As String
            Dim NumberPosition As Long
            Dim CommaPos As Long
            Dim NumberToIdentify As String
            Dim ZeroCount As Integer
            Dim DecimalNumber As Integer
            Dim Result As String
    
    
            'get the number without decimal points
            Try
                FormattedNumber = Format(CDbl(Number), "#####0.00")
            Catch
                MsgBox("That Number is not valid.", MsgBoxStyle.Critical)
                Exit Function
            End Try
    
            DecimalNumber = CDbl(Microsoft.VisualBasic.Right(FormattedNumber, 2))
            FormattedNumber = Microsoft.VisualBasic.Left(FormattedNumber, Len(FormattedNumber) - 3)
    
            Result = ""
    
            Select Case Len(CStr(FormattedNumber))
    
                Case 1
                    '9 or less
                    Result = ReturnSingleNumber(Format(CDbl(FormattedNumber), "#####0"))
                Case 2
                    '99 or less
                    Result = ReturnTensNumber(CStr(Format(CDbl(FormattedNumber), "#####0")))
                Case 3
                    '999 or less
                    Result = ReturnHundreds(CStr(Format(CDbl(FormattedNumber), "#####0"))) & " " & ReturnTensNumber(CStr(Format(CDbl(Microsoft.VisualBasic.Right(FormattedNumber, 2)), "#####0")))
                Case Is > 3
                    'this number is above the thousands. Determine where it lies, and assemble
                    'the string
                    CommaPos = 1
                    'format the number to lead 0's if the number is not a hundreds of it's type:
                    'such as 5,302 would be 005,302. When converted back to a number
                    'it would read 5,302 again.
                    If Len(FormattedNumber) <= 6 And Len(FormattedNumber) >= 4 Then
                        'thousands
                        FormattedNumber = CStr(Format(CDbl(FormattedNumber), "0##,##0"))
                    ElseIf Len(FormattedNumber) <= 9 And Len(FormattedNumber) >= 7 Then
                        FormattedNumber = CStr(Format(CDbl(FormattedNumber), "0##,0##,##0"))
                    ElseIf Len(FormattedNumber) <= 12 And Len(FormattedNumber) >= 10 Then
                        FormattedNumber = CStr(Format(CDbl(FormattedNumber), "0##,0##,0##,##0"))
    
                    End If
    
    
                    Do While CommaPos <> 0
    
                        CommaPos = InStr(CommaPos + 1, FormattedNumber, ",", CompareMethod.Text)
    
                        If CommaPos <> 0 Then
                            NumberToIdentify = Mid(FormattedNumber, CommaPos - 3, 3)
    
                            'get the position of this number. A 4 is a thousand, an 8 is a million, and a 12 is a billion
                            NumberPosition = (Len(FormattedNumber) - CommaPos) + 1
    
                            'convert back to an integer so we can determine how this will work
                            NumberToIdentify = CInt(NumberToIdentify)
    
                            If NumberToIdentify <> 0 Then
                                Select Case Len(NumberToIdentify)
                                    Case 1
                                        '9 or less
                                        Select Case NumberPosition
                                            'also, add the appropriate number here, such as thousand
                                        Case 4
                                                Result = Result & ReturnSingleNumber(Format(CDbl(NumberToIdentify), "#####0")) & " THOUSAND "
                                            Case 8
                                                Result = Result & ReturnSingleNumber(Format(CDbl(NumberToIdentify), "#####0")) & " MILLION "
                                            Case 12
                                                Result = Result & ReturnSingleNumber(Format(CDbl(NumberToIdentify), "#####0")) & " BILLION "
                                        End Select
                                    Case 2
                                        '99 or less
                                        Select Case NumberPosition
                                            'also, add the appropriate number here, such as thousand
                                        Case 4
                                                Result = Result & ReturnTensNumber(Format(CDbl(NumberToIdentify), "#####0")) & " THOUSAND "
                                            Case 8
                                                Result = Result & ReturnTensNumber(Format(CDbl(NumberToIdentify), "#####0")) & " MILLION "
                                            Case 12
                                                Result = Result & ReturnTensNumber(Format(CDbl(NumberToIdentify), "#####0")) & " BILLION "
                                        End Select
                                    Case 3
                                        '999 or less
                                        Select Case NumberPosition
                                            'also, add the appropriate number here, such as thousand
                                        Case 4
                                                Result = Result & ReturnHundreds(CStr(Format(CDbl(NumberToIdentify), "#####0"))) & " " & ReturnTensNumber(CStr(Format(CDbl(Microsoft.VisualBasic.Right(NumberToIdentify, 2)), "#####0"))) & " THOUSAND "
                                            Case 8
                                                Result = Result & ReturnHundreds(CStr(Format(CDbl(NumberToIdentify), "#####0"))) & " " & ReturnTensNumber(CStr(Format(CDbl(Microsoft.VisualBasic.Right(NumberToIdentify, 2)), "#####0"))) & " MILLION "
                                            Case 12
                                                Result = Result & ReturnHundreds(CStr(Format(CDbl(NumberToIdentify), "#####0"))) & " " & ReturnTensNumber(CStr(Format(CDbl(Microsoft.VisualBasic.Right(NumberToIdentify, 2)), "#####0"))) & " BILLION "
                                        End Select
                                End Select
                            End If
                        Else
                            ZeroCount = ZeroCount + 1
    
                            If ZeroCount = 1 Then
                                'we are at the end of this number. Get the last hundred, even if it
                                'isn't a hundred
                                FormattedNumber = Microsoft.VisualBasic.Right(FormattedNumber, 3)
    
                                FormattedNumber = CStr(Format(CDbl(FormattedNumber), "##0"))
    
                                FormattedNumber = CInt(FormattedNumber)
    
                                Select Case Len(FormattedNumber)
    
                                    Case 1
                                        '9 or less
                                        Result = Result & " " & ReturnSingleNumber(Format(CDbl(FormattedNumber), "#####0"))
                                    Case 2
                                        '99 or less
                                        Result = Result & " " & ReturnTensNumber(CStr(Format(CDbl(FormattedNumber), "#####0")))
                                    Case 3
                                        '999 or less
                                        Result = Result & " " & ReturnHundreds(CStr(Format(CDbl(FormattedNumber), "#####0"))) & " " & ReturnTensNumber(CStr(Format(CDbl(Microsoft.VisualBasic.Right(FormattedNumber, 2)), "#####0")))
                                End Select
    
                            End If
                        End If
    
                    Loop
    
            End Select
    
            'do the decimal, if there is one
    
            Result = Result.Trim & " DOLLARS AND " & Format(CInt(DecimalNumber), "#0") & "/100 CENTS"
    
            ReturnWordsFromNumber = Result
    
        End Function
        Private Shared Function ReturnSingleNumber(ByVal Number As String) As String
            Select Case CInt(Number)
    
                Case 1
                    ReturnSingleNumber = "ONE"
                Case 2
                    ReturnSingleNumber = "TWO"
                Case 3
                    ReturnSingleNumber = "THREE"
                Case 4
                    ReturnSingleNumber = "FOUR"
                Case 5
                    ReturnSingleNumber = "FIVE"
                Case 6
                    ReturnSingleNumber = "SIX"
                Case 7
                    ReturnSingleNumber = "SEVEN"
                Case 8
                    ReturnSingleNumber = "EIGHT"
                Case 9
                    ReturnSingleNumber = "NINE"
            End Select
        End Function
    
        Private Shared Function ReturnTensNumber(ByVal Number As String) As String
            Number = CInt(Number)
    
            If Number < 10 Then
                ReturnTensNumber = ReturnSingleNumber(Number)
            ElseIf Number = 10 Then
                ReturnTensNumber = "TEN"
            ElseIf Number = 11 Then
                ReturnTensNumber = "ELEVEN"
            ElseIf Number = 12 Then
                ReturnTensNumber = "TWELVE"
            ElseIf Number = 13 Then
                ReturnTensNumber = "THIRTEEN"
            ElseIf Number = 14 Then
                ReturnTensNumber = "FOURTEEN"
            ElseIf Number = 15 Then
                ReturnTensNumber = "FIFTEEN"
            ElseIf Number = 16 Then
                ReturnTensNumber = "SIXTEEN"
            ElseIf Number = 17 Then
                ReturnTensNumber = "SEVENTEEN"
            ElseIf Number = 18 Then
                ReturnTensNumber = "EIGHTEEN"
            ElseIf Number = 19 Then
                ReturnTensNumber = "NINETEEN"
            ElseIf Number = 20 Then
                ReturnTensNumber = "TWENTY"
            ElseIf Number = 30 Then
                ReturnTensNumber = "THIRTY"
            ElseIf Number = 40 Then
                ReturnTensNumber = "FORTY"
            ElseIf Number = 50 Then
                ReturnTensNumber = "FIFTY"
            ElseIf Number = 60 Then
                ReturnTensNumber = "SIXTY"
            ElseIf Number = 70 Then
                ReturnTensNumber = "SEVENTY"
            ElseIf Number = 80 Then
                ReturnTensNumber = "EIGHTY"
            ElseIf Number = 90 Then
                ReturnTensNumber = "NINETY"
            ElseIf Number >= 21 And Number <= 29 Then
                ReturnTensNumber = "TWENTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 31 And Number <= 39 Then
                ReturnTensNumber = "THIRTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 41 And Number <= 49 Then
                ReturnTensNumber = "FORTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 51 And Number <= 59 Then
                ReturnTensNumber = "FIFTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 61 And Number <= 69 Then
                ReturnTensNumber = "SIXTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 71 And Number <= 79 Then
                ReturnTensNumber = "SEVENTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 81 And Number <= 89 Then
                ReturnTensNumber = "EIGHTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 91 And Number <= 99 Then
                ReturnTensNumber = "NINETY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            End If
    
    
        End Function
    
        Private Shared Function ReturnHundreds(ByVal Number As String) As String
            ReturnHundreds = ReturnSingleNumber(Microsoft.VisualBasic.Left(Number, 1)) & " HUNDRED"
        End Function
    
    End Class
    
    


    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
    • Marked as answer by Kee Poppy Friday, November 11, 2011 9:08 AM
    Friday, November 4, 2011 5:26 PM
  • Here another way .. a bit shorter

     

    Public Class Form1
    
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            Label1.Text = ConvertToText(CInt(TextBox1.Text))
        End Sub
    
    
        Function ConvertToText(ByVal N As Long) As String
    
            Dim Powers() As String = {"Trillion", "Billion ", "Million ", "Thousand ", ""}
    
            Dim Div As Long = 1000000000000
            Dim Result As String = ""
            For Each S As String In Powers
                Dim Pow = N \ Div
                If Pow > 0 Then
                    Result &= ConvertHundredsToText(Pow) & S
                    N -= Pow * Div
                End If
                Div \= 1000
            Next
            Return Result
        End Function
    
        Function ConvertHundredsToText(ByVal nb As Long) As String
            Dim Basic() As String = {"", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten", _
             "Eleven ", "Twelve ", "Thirteen ", "Forteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Neneteen "}
            Dim Dix() As String = {"", "", "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "}
            Dim N = CInt(nb)
            Dim Centaine = N \ 100
            Dim Cent As String = Basic(Centaine)
            If Cent <> "" Then Cent &= "Hundred "
            N -= Centaine * 100
            Dim Dizaine = N \ 10
            If Dizaine > 1 Then
                Cent &= Dix(Dizaine)
                N -= Dizaine * 10
                Cent &= Basic(N)
            Else
                Cent &= Basic(N)
            End If
            Return Cent
        End Function
    
    End Class
    

     

    • Marked as answer by Kee Poppy Friday, November 11, 2011 9:08 AM
    Friday, November 4, 2011 9:05 PM
    • Marked as answer by Kee Poppy Friday, November 11, 2011 9:08 AM
    Friday, November 4, 2011 8:49 PM
  • I also covered this one a few years back.  I wrote about it here:  http://codemidden.wordpress.com/2011/05/08/parsing-large-numbers-to-words-english/

     

    • Marked as answer by Kee Poppy Friday, November 11, 2011 9:08 AM
    Friday, November 4, 2011 9:37 PM

All replies

  • I didn't write this, but had it tucked away in a "useful code" folder... It was designed to take numerics and output the text for check writing, so it will append things like "dollars" to the string, but you should be able to edit it to your specific needs.

    Option Strict Off
    
    Public Class NumberToWord
        Dim mNos(99) As String
    
        Public Shared Function Convert(ByVal Num As String) As String
            Return ReturnWordsFromNumber(Num)
        End Function
        Public Shared Function Convert(ByVal Num As Integer) As String
            Return ReturnWordsFromNumber(Num.ToString)
        End Function
        Public Shared Function Convert(ByVal Num As Double) As String
            Return ReturnWordsFromNumber(Num.ToString)
        End Function
        Public Shared Function Convert(ByVal Num As Decimal) As String
            Return ReturnWordsFromNumber(Num.ToString)
        End Function
        Private Shared Function ReturnWordsFromNumber(ByVal Number As String) As String
            Dim FormattedNumber As String
            Dim NumberPosition As Long
            Dim CommaPos As Long
            Dim NumberToIdentify As String
            Dim ZeroCount As Integer
            Dim DecimalNumber As Integer
            Dim Result As String
    
    
            'get the number without decimal points
            Try
                FormattedNumber = Format(CDbl(Number), "#####0.00")
            Catch
                MsgBox("That Number is not valid.", MsgBoxStyle.Critical)
                Exit Function
            End Try
    
            DecimalNumber = CDbl(Microsoft.VisualBasic.Right(FormattedNumber, 2))
            FormattedNumber = Microsoft.VisualBasic.Left(FormattedNumber, Len(FormattedNumber) - 3)
    
            Result = ""
    
            Select Case Len(CStr(FormattedNumber))
    
                Case 1
                    '9 or less
                    Result = ReturnSingleNumber(Format(CDbl(FormattedNumber), "#####0"))
                Case 2
                    '99 or less
                    Result = ReturnTensNumber(CStr(Format(CDbl(FormattedNumber), "#####0")))
                Case 3
                    '999 or less
                    Result = ReturnHundreds(CStr(Format(CDbl(FormattedNumber), "#####0"))) & " " & ReturnTensNumber(CStr(Format(CDbl(Microsoft.VisualBasic.Right(FormattedNumber, 2)), "#####0")))
                Case Is > 3
                    'this number is above the thousands. Determine where it lies, and assemble
                    'the string
                    CommaPos = 1
                    'format the number to lead 0's if the number is not a hundreds of it's type:
                    'such as 5,302 would be 005,302. When converted back to a number
                    'it would read 5,302 again.
                    If Len(FormattedNumber) <= 6 And Len(FormattedNumber) >= 4 Then
                        'thousands
                        FormattedNumber = CStr(Format(CDbl(FormattedNumber), "0##,##0"))
                    ElseIf Len(FormattedNumber) <= 9 And Len(FormattedNumber) >= 7 Then
                        FormattedNumber = CStr(Format(CDbl(FormattedNumber), "0##,0##,##0"))
                    ElseIf Len(FormattedNumber) <= 12 And Len(FormattedNumber) >= 10 Then
                        FormattedNumber = CStr(Format(CDbl(FormattedNumber), "0##,0##,0##,##0"))
    
                    End If
    
    
                    Do While CommaPos <> 0
    
                        CommaPos = InStr(CommaPos + 1, FormattedNumber, ",", CompareMethod.Text)
    
                        If CommaPos <> 0 Then
                            NumberToIdentify = Mid(FormattedNumber, CommaPos - 3, 3)
    
                            'get the position of this number. A 4 is a thousand, an 8 is a million, and a 12 is a billion
                            NumberPosition = (Len(FormattedNumber) - CommaPos) + 1
    
                            'convert back to an integer so we can determine how this will work
                            NumberToIdentify = CInt(NumberToIdentify)
    
                            If NumberToIdentify <> 0 Then
                                Select Case Len(NumberToIdentify)
                                    Case 1
                                        '9 or less
                                        Select Case NumberPosition
                                            'also, add the appropriate number here, such as thousand
                                        Case 4
                                                Result = Result & ReturnSingleNumber(Format(CDbl(NumberToIdentify), "#####0")) & " THOUSAND "
                                            Case 8
                                                Result = Result & ReturnSingleNumber(Format(CDbl(NumberToIdentify), "#####0")) & " MILLION "
                                            Case 12
                                                Result = Result & ReturnSingleNumber(Format(CDbl(NumberToIdentify), "#####0")) & " BILLION "
                                        End Select
                                    Case 2
                                        '99 or less
                                        Select Case NumberPosition
                                            'also, add the appropriate number here, such as thousand
                                        Case 4
                                                Result = Result & ReturnTensNumber(Format(CDbl(NumberToIdentify), "#####0")) & " THOUSAND "
                                            Case 8
                                                Result = Result & ReturnTensNumber(Format(CDbl(NumberToIdentify), "#####0")) & " MILLION "
                                            Case 12
                                                Result = Result & ReturnTensNumber(Format(CDbl(NumberToIdentify), "#####0")) & " BILLION "
                                        End Select
                                    Case 3
                                        '999 or less
                                        Select Case NumberPosition
                                            'also, add the appropriate number here, such as thousand
                                        Case 4
                                                Result = Result & ReturnHundreds(CStr(Format(CDbl(NumberToIdentify), "#####0"))) & " " & ReturnTensNumber(CStr(Format(CDbl(Microsoft.VisualBasic.Right(NumberToIdentify, 2)), "#####0"))) & " THOUSAND "
                                            Case 8
                                                Result = Result & ReturnHundreds(CStr(Format(CDbl(NumberToIdentify), "#####0"))) & " " & ReturnTensNumber(CStr(Format(CDbl(Microsoft.VisualBasic.Right(NumberToIdentify, 2)), "#####0"))) & " MILLION "
                                            Case 12
                                                Result = Result & ReturnHundreds(CStr(Format(CDbl(NumberToIdentify), "#####0"))) & " " & ReturnTensNumber(CStr(Format(CDbl(Microsoft.VisualBasic.Right(NumberToIdentify, 2)), "#####0"))) & " BILLION "
                                        End Select
                                End Select
                            End If
                        Else
                            ZeroCount = ZeroCount + 1
    
                            If ZeroCount = 1 Then
                                'we are at the end of this number. Get the last hundred, even if it
                                'isn't a hundred
                                FormattedNumber = Microsoft.VisualBasic.Right(FormattedNumber, 3)
    
                                FormattedNumber = CStr(Format(CDbl(FormattedNumber), "##0"))
    
                                FormattedNumber = CInt(FormattedNumber)
    
                                Select Case Len(FormattedNumber)
    
                                    Case 1
                                        '9 or less
                                        Result = Result & " " & ReturnSingleNumber(Format(CDbl(FormattedNumber), "#####0"))
                                    Case 2
                                        '99 or less
                                        Result = Result & " " & ReturnTensNumber(CStr(Format(CDbl(FormattedNumber), "#####0")))
                                    Case 3
                                        '999 or less
                                        Result = Result & " " & ReturnHundreds(CStr(Format(CDbl(FormattedNumber), "#####0"))) & " " & ReturnTensNumber(CStr(Format(CDbl(Microsoft.VisualBasic.Right(FormattedNumber, 2)), "#####0")))
                                End Select
    
                            End If
                        End If
    
                    Loop
    
            End Select
    
            'do the decimal, if there is one
    
            Result = Result.Trim & " DOLLARS AND " & Format(CInt(DecimalNumber), "#0") & "/100 CENTS"
    
            ReturnWordsFromNumber = Result
    
        End Function
        Private Shared Function ReturnSingleNumber(ByVal Number As String) As String
            Select Case CInt(Number)
    
                Case 1
                    ReturnSingleNumber = "ONE"
                Case 2
                    ReturnSingleNumber = "TWO"
                Case 3
                    ReturnSingleNumber = "THREE"
                Case 4
                    ReturnSingleNumber = "FOUR"
                Case 5
                    ReturnSingleNumber = "FIVE"
                Case 6
                    ReturnSingleNumber = "SIX"
                Case 7
                    ReturnSingleNumber = "SEVEN"
                Case 8
                    ReturnSingleNumber = "EIGHT"
                Case 9
                    ReturnSingleNumber = "NINE"
            End Select
        End Function
    
        Private Shared Function ReturnTensNumber(ByVal Number As String) As String
            Number = CInt(Number)
    
            If Number < 10 Then
                ReturnTensNumber = ReturnSingleNumber(Number)
            ElseIf Number = 10 Then
                ReturnTensNumber = "TEN"
            ElseIf Number = 11 Then
                ReturnTensNumber = "ELEVEN"
            ElseIf Number = 12 Then
                ReturnTensNumber = "TWELVE"
            ElseIf Number = 13 Then
                ReturnTensNumber = "THIRTEEN"
            ElseIf Number = 14 Then
                ReturnTensNumber = "FOURTEEN"
            ElseIf Number = 15 Then
                ReturnTensNumber = "FIFTEEN"
            ElseIf Number = 16 Then
                ReturnTensNumber = "SIXTEEN"
            ElseIf Number = 17 Then
                ReturnTensNumber = "SEVENTEEN"
            ElseIf Number = 18 Then
                ReturnTensNumber = "EIGHTEEN"
            ElseIf Number = 19 Then
                ReturnTensNumber = "NINETEEN"
            ElseIf Number = 20 Then
                ReturnTensNumber = "TWENTY"
            ElseIf Number = 30 Then
                ReturnTensNumber = "THIRTY"
            ElseIf Number = 40 Then
                ReturnTensNumber = "FORTY"
            ElseIf Number = 50 Then
                ReturnTensNumber = "FIFTY"
            ElseIf Number = 60 Then
                ReturnTensNumber = "SIXTY"
            ElseIf Number = 70 Then
                ReturnTensNumber = "SEVENTY"
            ElseIf Number = 80 Then
                ReturnTensNumber = "EIGHTY"
            ElseIf Number = 90 Then
                ReturnTensNumber = "NINETY"
            ElseIf Number >= 21 And Number <= 29 Then
                ReturnTensNumber = "TWENTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 31 And Number <= 39 Then
                ReturnTensNumber = "THIRTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 41 And Number <= 49 Then
                ReturnTensNumber = "FORTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 51 And Number <= 59 Then
                ReturnTensNumber = "FIFTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 61 And Number <= 69 Then
                ReturnTensNumber = "SIXTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 71 And Number <= 79 Then
                ReturnTensNumber = "SEVENTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 81 And Number <= 89 Then
                ReturnTensNumber = "EIGHTY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            ElseIf Number >= 91 And Number <= 99 Then
                ReturnTensNumber = "NINETY" & " " & ReturnSingleNumber(Microsoft.VisualBasic.Right(Number, 1))
            End If
    
    
        End Function
    
        Private Shared Function ReturnHundreds(ByVal Number As String) As String
            ReturnHundreds = ReturnSingleNumber(Microsoft.VisualBasic.Left(Number, 1)) & " HUNDRED"
        End Function
    
    End Class
    
    


    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
    • Marked as answer by Kee Poppy Friday, November 11, 2011 9:08 AM
    Friday, November 4, 2011 5:26 PM
    • Marked as answer by Kee Poppy Friday, November 11, 2011 9:08 AM
    Friday, November 4, 2011 8:49 PM
  • Here another way .. a bit shorter

     

    Public Class Form1
    
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            Label1.Text = ConvertToText(CInt(TextBox1.Text))
        End Sub
    
    
        Function ConvertToText(ByVal N As Long) As String
    
            Dim Powers() As String = {"Trillion", "Billion ", "Million ", "Thousand ", ""}
    
            Dim Div As Long = 1000000000000
            Dim Result As String = ""
            For Each S As String In Powers
                Dim Pow = N \ Div
                If Pow > 0 Then
                    Result &= ConvertHundredsToText(Pow) & S
                    N -= Pow * Div
                End If
                Div \= 1000
            Next
            Return Result
        End Function
    
        Function ConvertHundredsToText(ByVal nb As Long) As String
            Dim Basic() As String = {"", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten", _
             "Eleven ", "Twelve ", "Thirteen ", "Forteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Neneteen "}
            Dim Dix() As String = {"", "", "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety "}
            Dim N = CInt(nb)
            Dim Centaine = N \ 100
            Dim Cent As String = Basic(Centaine)
            If Cent <> "" Then Cent &= "Hundred "
            N -= Centaine * 100
            Dim Dizaine = N \ 10
            If Dizaine > 1 Then
                Cent &= Dix(Dizaine)
                N -= Dizaine * 10
                Cent &= Basic(N)
            Else
                Cent &= Basic(N)
            End If
            Return Cent
        End Function
    
    End Class
    

     

    • Marked as answer by Kee Poppy Friday, November 11, 2011 9:08 AM
    Friday, November 4, 2011 9:05 PM
  • I also covered this one a few years back.  I wrote about it here:  http://codemidden.wordpress.com/2011/05/08/parsing-large-numbers-to-words-english/

     

    • Marked as answer by Kee Poppy Friday, November 11, 2011 9:08 AM
    Friday, November 4, 2011 9:37 PM