Sunday, March 28, 2010

Convert number to word

Convert number to word



  Dim n As Long
         'The output is saved in variable strOutPut.
        Dim strOutPut As String = ""
        Dim l, r As Integer

        
        'Here 74 is considred as input.You may change as
        'per your requirement.
        n = 74
        'Get the floor value
        l = Math.Floor(n / 10)
        r = n Mod 10
        If l = 1 Then
            'For returning number from 10 to 19
            Select Case r
                Case 0
                    strOutPut = strOutPut & " Ten"
                Case 1
                    strOutPut = strOutPut & " Eleven"
                Case 2
                    strOutPut = strOutPut & " Twelve"
                Case 3
                    strOutPut = strOutPut & " Thirteen"
                Case 4
                    strOutPut = strOutPut & " Fourteen"
                Case 5
                    strOutPut = strOutPut & " Fifteen"
                Case 6
                    strOutPut = strOutPut & " Sixteen"
                Case 7
                    strOutPut = strOutPut & " Seventeen"
                Case 8
                    strOutPut = strOutPut & " Eighteen"
                Case 9
                    strOutPut = strOutPut & " Nineteen"
            End Select
        Else
            'For returning the number in multiple of 10.
            Select Case l
                Case 2
                    strOutPut = strOutPut & " Twenty"
                Case 3
                    strOutPut = strOutPut & " Thirty"
                Case 4
                    strOutPut = strOutPut & " Forty"
                Case 5
                    strOutPut = strOutPut & " Fifty"
                Case 6
                    strOutPut = strOutPut & " Sixty"
                Case 7
                    strOutPut = strOutPut & " Seventy"
                Case 8
                    strOutPut = strOutPut & " Eighty"
                Case 9
                    strOutPut = strOutPut & " Ninety"
            End Select
            'For returning single digit number.
            Select Case r
                Case 1
                    strOutPut = strOutPut & " One"
                Case 2
                    strOutPut = strOutPut & " Two"
                Case 3
                    strOutPut = strOutPut & " Three"
                Case 4
                    strOutPut = strOutPut & " Four"
                Case 5
                    strOutPut = strOutPut & " Five"
                Case 6
                    strOutPut = strOutPut & " Six"
                Case 7
                    strOutPut = strOutPut & " Seven"
                Case 8
                    strOutPut = strOutPut & " Eight"
                Case 9
                    strOutPut = strOutPut & " Nine"
            End Select
        End If
        MessageBox.Show(strOutPut)