VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 4560 ClientLeft = 60 ClientTop = 450 ClientWidth = 16395 LinkTopic = "Form1" ScaleHeight = 4560 ScaleWidth = 16395 StartUpPosition = 3 'Windows Default Begin VB.CommandButton Command1 Caption = "Convert" Height = 495 Left = 5880 TabIndex = 2 Top = 3000 Width = 1215 End Begin VB.TextBox txtOutputNumber Height = 1935 Left = 240 TabIndex = 1 Text = "txtOutputNumber" Top = 720 Width = 15855 End Begin VB.TextBox txtInputNumber Height = 285 Left = 240 TabIndex = 0 Text = "32768" Top = 240 Width = 9015 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False ' Copyright (c) Dave Hansen - Dave@thehansens.com 2007 - all rights reserved ' You have the right to use this code as long as you do not delete this copyright information ' Because of the way very large doubles are stored in scientific notation, the less significant digits ' get lost on these huge numbers. A 64 bit version of a long would be better than the use of a double ' but this is not available in vb6 ' You have the right to distribute this code as long as the initial copyright is left intact. ' Be careful, if you use this code for a homework assignment, your professor/teacher may be able to ' find this code on the internet just as easily as you did. Option Explicit Dim Ks(21) As String Dim Ones(20) As String Dim Tens(10) As String Dim thou As Double Dim Level As Integer Private Sub Command1_Click() Dim Number As Double Dim str As String Dim sign As String sign = "" Number = Val(txtInputNumber.Text) If Number < 0 Then Number = -Number sign = "Negative " End If Level = 0 str = sign & NumberToWords(Number, 0) If Right$(str, 1) = "," Then str = Left$(str, Len(str) - 1) End If txtOutputNumber.Text = str End Sub Private Sub Form_Load() thou = 1000# Ks(0) = "" Ks(1) = "Thousand" Ks(2) = "Million" Ks(3) = "Billion" Ks(4) = "Trillion" Ks(5) = "Quadrillion" Ks(6) = "Quintillion" Ks(7) = "Sextillion" Ks(8) = "Septillion" Ks(9) = "Octillion" Ks(10) = "Nonillion" Ks(11) = "Decillion" Ks(12) = "Undecillion" Ks(13) = "Duodecillion" Ks(14) = "Tredecillion" Ks(15) = "Quattuordecillion" Ks(16) = "Quindecillion" Ks(17) = "Sexdecillion" Ks(18) = "Septendecillion" Ks(19) = "Octodecillion" Ks(20) = "Novemdecillion" Ks(21) = "Vigintillion" Ones(0) = "" Ones(1) = "One" Ones(2) = "Two" Ones(3) = "Three" Ones(4) = "Four" Ones(5) = "Five" Ones(6) = "Six" Ones(7) = "Seven" Ones(8) = "Eight" Ones(9) = "Nine" Ones(10) = "Ten" Ones(11) = "Eleven" Ones(12) = "Twelve" Ones(13) = "Thirteen" Ones(14) = "Fourteen" Ones(15) = "Fifteen" Ones(16) = "Sixteen" Ones(17) = "Seventeen" Ones(18) = "Eighteen" Ones(19) = "Nineteen" Tens(0) = "" Tens(1) = "Ten" Tens(2) = "Twenty" Tens(3) = "Thirty" Tens(4) = "Fourty" Tens(5) = "Fifty" Tens(6) = "Sixty" Tens(7) = "Seventy" Tens(8) = "Eighty" Tens(9) = "Ninety" End Sub Function NumberToWords(Number As Double, Level As Integer) As String Dim rc As String Dim rc2 As String Dim i As Integer Dim output_something As Boolean output_something = False rc = "" If Number >= 1000 Then rc2 = NumberToWords(Fix(Number / thou), Level + 1) If rc2 <> "" Then If Right$(rc2, 2) <> ", " Then rc = rc2 & ", " Else rc = rc2 End If End If End If Number = ModThousand(Number) If Number = 0 And Level > 0 Then NumberToWords = rc Exit Function End If If Number >= 100 Then i = Number \ 100 rc = rc & Ones(i) & " Hundred " output_something = True End If Number = Number Mod 100 If Number > 20 Then i = Number \ 10 rc = rc & Tens(i) & " " Number = Number Mod 10 output_something = True End If i = Int(Number) If Level = 0 And i = 0 And rc = "" Then rc = "Zero" NumberToWords = rc Exit Function End If i = Int(Number) If i <> 0 Or output_something Then rc = Trim(rc & Ones(i)) & " " If Level > 0 Then rc = rc & Ks(Level) End If End If NumberToWords = Trim(rc) End Function Function ModThousand(num As Double) As Double ' function to perform the mod 1000 function on a huge number Dim rc As Double Dim x As Double Dim divby As Double divby = 1000 x = Fix(num / divby) x = x * divby num = num - x ModThousand = num End Function