This script transforms a number in words.
It works fine but as I'm a non-native english speaker I don't know if the result is
correct english.
Especially for Billions. A few years ago some english and american friends of mine could
not agree on the value. In the scirpt are thousands of millions.
Hope a reader from Florida of this ng will appreciate. ;-)
I will not say his Name.
Bye.
Giovanni Cenati.
'************************************************
' File: From numbers to letters_test.vbs
' Author: Giovanni Cenati
' my address is at katamail dot com with name Reventlov
'************************************************
'SET FSO = CreateObject("Scripting.FileSystemObject")
'SET TextFile = FSO.CreateTextFile("test.txt", True)
'for i=23400000 to 23401700 step 17
'TextFile.Write i & " " & Trasformainlettere(i)
'TextFile.WriteLine
'next
'msgbox "end test"
A=inputbox("Number to be converted in letters:")
a=inputbox("Converted:",,Trasformainlettere(a))
wscript.quit
'-------------------------------------------------------
'************************************************
' File: Transforms to letters.vbs (function)
' Author: Giovanni Cenati
'
'************************************************
function TrasformaInLettere(byval n)
dim i, dec, lun, lett
dim tri(5)
n=cdbl(n)
num=cstr(fix(n))
Str=cstr("000000000000000000000"&num)
lun=len(Str)
for i=1 to 5
'cuts the string in pieces
tri(i)=mid(Str,lun-(i*3)+1,3)
'The number is now tri(5)& tri(4)& tri(3)& tri(2)& tri(1).
if tri(i)>0 then lett= TrasformaTerzina(tri(i),i) & lett
next
if lett="" then lett="zero" 'manages the zero
TrasformaInLettere= lett
end function
function TrasformaTerzina(tri,t)
'tri is "nnn" to be converted.
't is the number as below::
't=1 if the number is from 1 to 999
't=2 from 1000 to 999000, e.g. the thousands
't=3 are the millions, etc
dim ultimeduecifre,ris,decine,unita
dim n(30) 'all the figures in letters
n(0)=""
n(1)="one":n(2)="two":n(3)="three":n(4)="four":n(5)="five"
n(6)="six":n(7)="seven":n(8)="eight":n(9)="nine":n(10)="ten"
n(11)="eleven":n(12)="twelve":n(13)="thirteen":n(14)="fourteen":n(15)="fifteen"
n(16)="sixteen":n(17)="seventeen":n(18)="eighteeni":n(19)="nineteen"
n(22)="twenty":n(23)="thirty":n(24)="forty":n(25)="fifty"
n(26)="sixty":n(27)="seventy":n(28)="eighty":n(29)="ninety"
'manages the hundreds
if left(tri,1)>0 then ris=n(cint(left(tri,1)))&"hundred"
'if it is nxx then uses n+hundred
'manages numbers from 1 to 19 and from 20 on
Ultimeduecifre=cint(right(tri,2))
if Ultimeduecifre < 20 then
ris=ris&n(Ultimeduecifre) 'from 1 to 19 uses the array "n".
else
'manages separately tens and units from 20 then joins them
Decine=mid(tri,2,1) 'tens
Unita=right(tri,1) 'units
ris=ris & n(20+decine) 'from n(22) is twenty, n(23) is thirty,etc.
Ris=ris & n(Unita) 'adds one, two three...
end if
'manages the position of thousands, millions, etc.
if t=2 then
ris=ris&"thousand"
if tri=1 then ris="onethousand"
end if
if t=3 then
ris=ris&"millions"
if tri=1 then ris="onemillion"
end if
if t=4 then
ris=ris&"billions"
if tri=1 then ris="onebillion"
end if
if t=5 then
ris=ris&"thousandbillions"
if tri=1 then ris="onethoudandbillions"
end if
TrasformaTerzina=Ris
end function
'-------------------------------------------------------
--
Giovanni Cenati (Aosta, Italy)
Write to user "Reventlov" and domain at katamail com