VBCE.com - The Premier Website For Visual Basic/CE Developers

 

*Dev Corner

Sample Code
Controls
Workarounds
Tips & Tricks
Q & A
Forums

*Goodies
Downloads
Software
Bookstore


*General
Home
What's New
General Info
Misc. Info


*News Worthy
News
Articles
Editorials
KB Articles
Reviews
Awards

*Miscellaneous
Web Links
Partners
Search
Feedback
Advertising

Sponsors


More...


Convert Numbers to Words! - Download The Source!

Convert numbers to words with this easy to use set of functions.  Now, 5675 becomes Five Thousand Six Hundred Seventy Five.

'-- Sean Kelly - seank@microsoft.com
'-- Windows CE Tools

'-- Sean works for Microsoft in the CE tools division.
'-- The views and opinions expressed in the code are Sean's and
'-- do not necessarily represent those of his employer.

Convert numbers to words Source Code
Dim cvtText(30) As String

Private Sub cmdConvert_Click()
    MsgBox Cvt(txtNumber.Text)
End Sub

Private Sub Form_Load()

End Sub

 Private Sub cvtInit()
    cvtText(1) = "One"
    cvtText(2) = "Two"
    cvtText(3) = "Three"
    cvtText(4) = "Four"
    cvtText(5) = "Five"
    cvtText(6) = "Six"
    cvtText(7) = "Seven"
    cvtText(8) = "Eight"
    cvtText(9) = "Nine"
    cvtText(10) = "Ten"
    cvtText(11) = "Eleven"
    cvtText(12) = "Twelve"
    cvtText(13) = "Thirteen"
    cvtText(14) = "Fourteen"
    cvtText(15) = "Fifteen"
    cvtText(16) = "Sixteen"
    cvtText(17) = "Seventeen"
    cvtText(18) = "Eighteen"
    cvtText(19) = "Ninteen"
    cvtText(20) = "Twenty"
    cvtText(21) = "Thrity"
    cvtText(22) = "Forty"
    cvtText(23) = "Fifty"
    cvtText(24) = "Sixty"
    cvtText(25) = "Seventy"
    cvtText(26) = "Eigthty"
    cvtText(27) = "Ninty"
    cvtText(28) = "Hundred"
    cvtText(29) = "Thousand"
    cvtText(30) = "Million"
 End Sub

Private Function cvt100(ByVal x As Integer)
    Dim t As Integer
    
    If x > 999 Then
      cvt100 = "Error 100"
      Exit Function
    End If
    
    If x > 99 Then
      t = x \ 100
      cvt100 = cvtText(t) & " " & cvtText(28) & " "
      x = x - (t * 100)
    End If
    
    If x > 20 Then
      t = x \ 10
      cvt100 = cvt100 & cvtText(t + 18) & " "
      x = x - (t * 10)
    End If
    
    If x > 0 Then
      cvt100 = cvt100 & cvtText(x) & " "
    End If
End Function

Private Function Cvt(x As Long) As String
    Dim t As Long
    
    cvtInit
    
    If x > 999999999 Then
      Cvt = "Number to large"
      Exit Function
    End If
    
    If x > 999999 Then
      t = x \ 1000000
      Cvt = cvt100(t) & cvtText(30) & " "
      x = x - (t * 1000000)
    End If
    
    If x > 999 Then
      t = x \ 1000
      Cvt = Cvt & cvt100(t) & cvtText(29) & " "
      x = x - (t * 1000)
    End If
    
    If x > 0 Then
      Cvt = Cvt & cvt100(x)
    End If
End Function

 


VBCE.com is DevX Winner!

Unless otherwise noted, all information on VBCE.com is Copyright 1998 - 2002
Windows, Windows CE, and Visual Basic are trademarks of the Microsoft Corporation.
VBCE.com is not responsible for content on external sites.
Send all feedback to webmaster@vbce.com
Webmasters - feel free to link to
VBCE.com - Premier Website for Visual Basic/CE Development

Buy Books!