473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Code to convert a Number to a spelled out number

D
Does anyone have a VBA code that converts numbers to Spelled out numbers?
Example 100 to One Hundred. I need it for a check writing program and I
don't feel like reinventing the wheel.

Thanks
Nov 12 '05 #1
3 3044
On Mon, 16 Feb 2004 12:19:57 -0500 in comp.databases.ms-access, "D"
<D@D> wrote:
Does anyone have a VBA code that converts numbers to Spelled out numbers?
Example 100 to One Hundred. I need it for a check writing program and I
don't feel like reinventing the wheel.


You mean like 10^100 = Google?

http://tinyurl.com/32cah

--
A)bort, R)etry, I)nfluence with large hammer.
Nov 12 '05 #2

"D" <D@D> skrev i en meddelelse news:10*************@corp.supernews.com...
Does anyone have a VBA code that converts numbers to Spelled out numbers?
Example 100 to One Hundred. I need it for a check writing program and I
don't feel like reinventing the wheel.

Thanks


I have some code I've made.
It's in a mix of danish/english .... hope you will find your way ....
otherwise feel free to send me aprivate E-mail to ask.

I made it in Excel.
But most of it should work in Access.

You type in e.g. 100,25
The printed result is :
EtHundrede 25/100

Note :
Million is equal to billion in english :-)

Here is the code :

Public msTalOrd

Private Function TalTilBogstaver(ByVal Tal As Double) As String
TalTilBogstaver = _
Bogstavering(Tal, 1000000, "Million", "er") & _
Bogstavering(Tal, 1000, "Tusinde", "") & _
Bogstavering(Tal, 1, "", "") & _
" " & Format(FormatNumber(100 * (Tal - Int(Tal)), 0), "00") & "/100"
End Function

Private Function Bogstavering(ByVal Tal As Double, ByVal Enhed As Long,
ByVal Navn As String, ByVal Flertalsendelse As String) As String
Dim sTalStreng As String
Dim lIalt As Long
Dim lHundreder As Long
Dim lEnereOgTiere As Long
lIalt = (Int(Tal) \ Enhed) Mod 1000
lHundreder = lIalt \ 100 Mod 10
lEnereOgTiere = lIalt Mod 100
If lHundreder > 0 Then
sTalStreng = Bogstavering(lHundreder, 1, "Hundrede", "")
Else
sTalStreng = ""
End If
Select Case lEnereOgTiere
Case 1 To 19
sTalStreng = sTalStreng & msTalOrd(lEnereOgTiere)
Case 20 To 99
sTalStreng = sTalStreng & msTalOrd(lEnereOgTiere \ 10) & "ti" &
msTalOrd(lEnereOgTiere Mod 10)
End Select
If lIalt = 0 Then
Bogstavering = ""
ElseIf lIalt = 1 Then
Bogstavering = sTalStreng & Navn
ElseIf lIalt > 1 Then
Bogstavering = sTalStreng & Navn & Flertalsendelse
End If
End Function

Sub Konverter_Til_Talord()
msTalOrd = Array("", "Et", "To", "Tre", "Fire", "Fem", "Seks", "Syv", _
"Otte", "Ni", "Ti", "Elleve", "Tolv", "Tretten", "Fjorten", _
"Femten", "Seksten", "Sytten", "Atten", "Nitten")

' Take the number from celle E4
Worksheets("Check_Indtastning").Range("F1").Activa te
valgt_Tal = ActiveCell.Value

' Konverter det
ud_tal = TalTilBogstaver(valgt_Tal)

' Write it Worksheets("Check_Indtastning").Range("B3").Activa te
ActiveCell.Value = ud_tal

End Sub
Nov 12 '05 #3
"Jan Jørgensen" <xxjjj1@pcdk (fjern xx)> wrote in message news:<40***********************@dread15.news.tele. dk>...
"D" <D@D> skrev i en meddelelse news:10*************@corp.supernews.com...
Does anyone have a VBA code that converts numbers to Spelled out numbers?
Example 100 to One Hundred. I need it for a check writing program and I
don't feel like reinventing the wheel.

Thanks


Use this, it works great. I use it for my Payroll and Accounts payable program.

'************ Code Start **********
'This code was originally written by Joe Foster.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Joe Foster
'
' Convert a currency value into an (American) English string
Function English(ByVal N As Currency) As String
Const Thousand = 1000@
Const Million = Thousand * Thousand
Const Billion = Thousand * Million
Const Trillion = Thousand * Billion

If (N = 0@) Then English = "zero": Exit Function

Dim Buf As String: If (N < 0@) Then Buf = "negative " Else Buf = ""
Dim Frac As Currency: Frac = Abs(N - Fix(N))
If (N < 0@ Or Frac <> 0@) Then N = Abs(Fix(N))
Dim AtLeastOne As Integer: AtLeastOne = N >= 1

If (N >= Trillion) Then
Debug.Print N
Buf = Buf & EnglishDigitGroup(Int(N / Trillion)) & " Trillion"
N = N - Int(N / Trillion) * Trillion ' Mod overflows
If (N >= 1@) Then Buf = Buf & " "
End If

If (N >= Billion) Then
Debug.Print N
Buf = Buf & EnglishDigitGroup(Int(N / Billion)) & " Billion"
N = N - Int(N / Billion) * Billion ' Mod still overflows
If (N >= 1@) Then Buf = Buf & " "
End If

If (N >= Million) Then
Debug.Print N
Buf = Buf & EnglishDigitGroup(N \ Million) & " Million"
N = N Mod Million
If (N >= 1@) Then Buf = Buf & " "
End If

If (N >= Thousand) Then
Debug.Print N
Buf = Buf & EnglishDigitGroup(N \ Thousand) & " Thousand"
N = N Mod Thousand
If (N >= 1@) Then Buf = Buf & " "
End If

If (N >= 1@) Then
Debug.Print N
Buf = Buf & EnglishDigitGroup(N)
End If

If (Frac = 0@) Then
'Buf = Buf & " Exactly"
Buf = Buf & " and 00/100"
ElseIf (Int(Frac * 100@) = Frac * 100@) Then
If AtLeastOne Then Buf = Buf & " and "
Buf = Buf & Format$(Frac * 100@, "00") & "/100"
Else
If AtLeastOne Then Buf = Buf & " and "
Buf = Buf & Format$(Frac * 10000@, "0000") & "/10000"
End If

English = Buf
End Function

' Support function to be used only by English()
Private Function EnglishDigitGroup(ByVal N As Integer) As String
Const Hundred = " Hundred"
Const One = "One"
Const Two = "Two"
Const Three = "Three"
Const Four = "Four"
Const Five = "Five"
Const Six = "Six"
Const Seven = "Seven"
Const Eight = "Eight"
Const Nine = "Nine"
Dim Buf As String: Buf = ""
Dim Flag As Integer: Flag = False

'Do hundreds
Select Case (N \ 100)
Case 0: Buf = "": Flag = False
Case 1: Buf = One & Hundred: Flag = True
Case 2: Buf = Two & Hundred: Flag = True
Case 3: Buf = Three & Hundred: Flag = True
Case 4: Buf = Four & Hundred: Flag = True
Case 5: Buf = Five & Hundred: Flag = True
Case 6: Buf = Six & Hundred: Flag = True
Case 7: Buf = Seven & Hundred: Flag = True
Case 8: Buf = Eight & Hundred: Flag = True
Case 9: Buf = Nine & Hundred: Flag = True
End Select

If (Flag <> False) Then N = N Mod 100
If (N > 0) Then
If (Flag <> False) Then Buf = Buf & " "
Else
EnglishDigitGroup = Buf
Exit Function
End If

'Do tens (except teens)
Select Case (N \ 10)
Case 0, 1: Flag = False
Case 2: Buf = Buf & "Twenty": Flag = True
Case 3: Buf = Buf & "Thirty": Flag = True
Case 4: Buf = Buf & "Forty": Flag = True
Case 5: Buf = Buf & "Fifty": Flag = True
Case 6: Buf = Buf & "Sixty": Flag = True
Case 7: Buf = Buf & "Seventy": Flag = True
Case 8: Buf = Buf & "Eighty": Flag = True
Case 9: Buf = Buf & "Ninety": Flag = True
End Select

If (Flag <> False) Then N = N Mod 10
If (N > 0) Then
If (Flag <> False) Then Buf = Buf & "-"
Else
EnglishDigitGroup = Buf
Exit Function
End If

'Do ones and teens
Select Case (N)
Case 0: ' do nothing
Case 1: Buf = Buf & One
Case 2: Buf = Buf & Two
Case 3: Buf = Buf & Three
Case 4: Buf = Buf & Four
Case 5: Buf = Buf & Five
Case 6: Buf = Buf & Six
Case 7: Buf = Buf & Seven
Case 8: Buf = Buf & Eight
Case 9: Buf = Buf & Nine
Case 10: Buf = Buf & "Ten"
Case 11: Buf = Buf & "Eleven"
Case 12: Buf = Buf & "Twelve"
Case 13: Buf = Buf & "Thirteen"
Case 14: Buf = Buf & "Fourteen"
Case 15: Buf = Buf & "Fifteen"
Case 16: Buf = Buf & "Sixteen"
Case 17: Buf = Buf & "Seventeen"
Case 18: Buf = Buf & "Eighteen"
Case 19: Buf = Buf & "Nineteen"
End Select

EnglishDigitGroup = Buf
End Function
'************ Code End **********
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: joemono | last post by:
Hello everyone! First, I appologize if this posting isn't proper "netiquette" for this group. I've been working with perl for almost 2 years now. However, my regular expression knowledge is...
84
by: Andy Glew | last post by:
I am in search of any rigourous, scientific, academic or industrial studies comparing naming conventions in C++ or similar languages such as Ada: Specifically, are names formed with...
2
by: mayur | last post by:
Hi, Can anyone help me with the following error I am getting in my asp.net application. The number name 'System.Web.UI.WebControls' contains more than the maximum number of prefixes. The maximum...
7
by: Rich Grise | last post by:
OK, I don't know if this is Off-Topic for the group(s), because "QT" isn't "Pure C++", and Slackware is a distro, but those guys are sharp. :-) And I've crossposted to sci.electroncs.design because...
3
by: rishabhshrivastava | last post by:
Hello All, How can I convert a value to Double in JavaScript??? In vbscript i believe its done as cDbl(Value) I tried lots of way but getting a value of "NaN". Any suggestions/ideas will...
19
by: VK | last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/ b495b4898808fde0> is more than one month old - this may pose problem for posting over some news servers. This is why I'm...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
1
by: santoshsri | last post by:
Hi below is a SQL Query written at SQL Server 2000. The result has been ordered by a.Location_Number , a.Transaction_Date, but in output the result is not ordered for eg : I am getting records for...
11
by: rm | last post by:
There is a Linux forum that I frequent from time to time on which I mentioned a couple of scripts that I wrote. The editors of a small Linux magazine heard and found them interesting enough to ask...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.