Вы находитесь на странице: 1из 1

Function ConvertToWords(ByVal vAmount As Variant) As String

Dim acSelection1() As Variant


Dim acSelection2() As Variant
Dim lcDigit()As Variant
Dim StrCount As Long
Const lcTeens = 2
Const lcHundreds = 3
Const lcThousands = 4
Const lcMillions = 7
Const lcBillions = 10
If vAmount = Empty Then GoTo ExitMe
acSelection1 = Array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen",
"Sixteen", "Seventeen", "Eighteen", "Nineteen")
acSelection2 = Array("", "", "Twenty-", "Thirty-", "Forty-", "Fifty-", "Sixty-"
, "Seventy-", "Eighty-", "Ninety-")
lcDigit = Array("", "", "", " Hundred ", " Thousand ", "", "", " Million ", "",
"", " Billion ")
StrCount = Len(vAmount)

Select Case StrCount


Case 1: ConvertToWords = acSelection1(Right$(vAmount, 1))
Case 2
If Left(Right$(vAmount, 2), 1) = 1 Then
ConvertToWords = acSelection1(Right$(vAmount, 2))
Else
ConvertToWords = acSelection2(Left(Right$(vAmount, 2), 1)) & acSelection1(Right$
(vAmount, 1))
End If
Case 3: ConvertToWords = acSelection1(Left(Right$(vAmount, 3), 1)) & lcDigit(lcH
undreds) & ConvertToWords(Right(Right$(vAmount, 3), 2))
Case 4 To 5: ConvertToWords = ConvertToWords(Left(vAmount, IIf(StrCount - lcThou
sands = 0, 1, 2))) & lcDigit(lcThousands) & IIf(Left(Right(vAmount, lcHundreds),
1) = 0, ConvertToWords(Right(vAmount, lcTeens)), ConvertToWords(Right(vAmount,
lcHundreds)))
Case 6: ConvertToWords = ConvertToWords(Right$(Left(vAmount, 3), 3)) & lcDigit(l
cThousands) & ConvertToWords(Right(vAmount, 3))
End Select
Exit Function
ExitMe:
ConvertToWords = 0
End Function

Вам также может понравиться