Check out my VB.NET code to convert numbers entered in a text box to string....It converts upto 99999999 though.....
Imports vb = Microsoft.VisualBasic
Public Class frmFigures
Private Function ConvertFigure(ByRef AmountInFigure As Double) As String
If Trim(AmountInFigure) <> "" Then
If AmountInFigure.ToString.Trim.Length = 1 Then
ConvertFigure = getOnces(AmountInFigure)
ElseIf AmountInFigure.ToString.Trim.Length = 2 Then
If vb.Left(AmountInFigure.ToString.Trim, 1) = 1 Then
ConvertFigure = getTens(AmountInFigure)
Else
ConvertFigure = getOtherTens(vb.Left(AmountInFigure.ToString.Trim, 1)) & " " & getOnces(vb.Right(AmountInFigure.ToString.Trim, 1)).ToLower
End If
ElseIf AmountInFigure.ToString.Trim.Length = 3 Then
If CInt(Mid(AmountInFigure, 2, 2)) = 0 Then
ConvertFigure = getOnces(Mid(Trim(AmountInFigure), 1, 1)) & " hundred "
ElseIf CInt(Mid(AmountInFigure, 2, 1)) >= 2 Then
ConvertFigure = (getOnces(vb.Left(AmountInFigure.ToString.Trim, 1))) & " hundred and " & getOtherTens(Mid(Trim(AmountInFigure), 2, 1)) & " " & LCase(getOnces(vb.Right(AmountInFigure.ToString.Trim, 1)))
ElseIf CInt(Mid(AmountInFigure, 2, 1)) = 1 Then
ConvertFigure = (getOnces(vb.Left(AmountInFigure.ToString.Trim, 1))) & " hundred and " & getTens(Mid(AmountInFigure, 2, 2))
Else
ConvertFigure = (getOnces(vb.Left(AmountInFigure.ToString.Trim, 1))) & " hundred and " & getOnces(Mid(AmountInFigure, 2, 2))
End If
ElseIf Len(Trim(AmountInFigure)) = 4 Then
ConvertFigure = ConvertFigure(Mid(AmountInFigure, 1, 1)) & " thousand " & ConvertFigure(Mid(AmountInFigure, 2, 3))
ElseIf Len(Trim(AmountInFigure)) = 5 Then
ConvertFigure = ConvertFigure(Mid(AmountInFigure, 1, 2)) & " thousand " & ConvertFigure(Mid(AmountInFigure, 3, 3))
ElseIf Len(Trim(AmountInFigure)) = 6 Then
ConvertFigure = ConvertFigure(Mid(AmountInFigure, 1, 3)) & " thousand " & ConvertFigure(Mid(AmountInFigure, 4, 3))
ElseIf Len(Trim(AmountInFigure)) = 7 Then
If Mid(AmountInFigure, 2, 6) = 0 Then
ConvertFigure = ConvertFigure(Mid(AmountInFigure, 1, 1)) & " million "
ElseIf Mid(AmountInFigure, 2, 3) = 0 Then
ConvertFigure = ConvertFigure(Mid(AmountInFigure, 1, 1)) & " million " & ConvertFigure(Mid(AmountInFigure, 5, 3))
Else
ConvertFigure = ConvertFigure(Mid(AmountInFigure, 1, 1)) & " million " & ConvertFigure(Mid(AmountInFigure, 2, 3)) & " thousand " & ConvertFigure(Mid(AmountInFigure, 5, 3))
End If
ElseIf Len(Trim(AmountInFigure)) = 8 Then
If Mid(AmountInFigure, 3, 6) = 0 Then
ConvertFigure = ConvertFigure(Mid(AmountInFigure, 1, 2)) & " million "
ElseIf Mid(AmountInFigure, 3, 3) = 0 Then
ConvertFigure = ConvertFigure(Mid(AmountInFigure, 1, 2)) & " million " & ConvertFigure(Mid(AmountInFigure, 6, 3))
Else
ConvertFigure = ConvertFigure(Mid(AmountInFigure, 1, 2)) & " million " & ConvertFigure(Mid(AmountInFigure, 3, 3)) & " thousand " & ConvertFigure(Mid(AmountInFigure, 6, 3))
End If
Else
ConvertFigure = ""
End If
Else
ConvertFigure = ""
End If
End Function
Private Function getOnces(ByRef figures As Double) As String
Select Case figures
Case 1
getOnces = "One"
Case 2
getOnces = "Two"
Case 3
getOnces = "Three"
Case 4
getOnces = "Four"
Case 5
getOnces = "Five"
Case 6
getOnces = "Six"
Case 7
getOnces = "Seven"
Case 8
getOnces = "Eight"
Case 9
getOnces = "Nine"
Case Else
getOnces = ""
End Select
End Function
Private Function getTens(ByRef figures As Double) As String
Select Case figures
Case 10
getTens = "Ten"
Case 11
getTens = "Eleven"
Case 12
getTens = "Twelve"
Case 13
getTens = "Thirteen"
Case 14
getTens = "Fourteen"
Case 15
getTens = "Fifteen"
Case 16
getTens = "Sixteen"
Case 17
getTens = "Seventeen"
Case 18
getTens = "eighteen"
Case 19
getTens = "Nineteen"
Case Else
getTens = ""
End Select
End Function
Private Function getOtherTens(ByRef figures As Double) As String
Select Case figures
Case 1
getOtherTens = ""
Case 2
getOtherTens = "Twenty"
Case 3
getOtherTens = "Thirty"
Case 4
getOtherTens = "Fourty"
Case 5
getOtherTens = "Fifty"
Case 6
getOtherTens = "Sixty"
Case 7
getOtherTens = "Seventy"
Case 8
getOtherTens = "Eighty"
Case 9
getOtherTens = "Ninety"
Case Else
getOtherTens = ""
End Select
End Function
Private Sub btnFigures_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFigures.Click
MessageBox.Show(ConvertFigure(txtFigures.Text))
End Sub
End Class