Сумма прописью
Данный код позволит вам отобразить число прописью (только проверь на повторение переменных в своей программе :num, razr, hundreds, tens, ones, razryad, t, o, result ,s, i, count)
Public Function ShortNum(num, razr)
Dim hundreds, tens, ones, razryad
hundreds = Array("", " сто", " двести", " триста", " четыреста", " пятьсот", " шестьсот", " семьсот", " восемьсот", " девятьсот")
tens = Array("", "", " двадцать", " тридцать", " сорок", " пятьдесят", " шестьдесят", " семьдесят", " восемьдесят", " девяносто")
ones = Array("", "", "", " три", " четыре", " пять", " шесть", " семь", " восемь", " девять", " десять", " одиннадцать", " двенадцать", " тринадцать", " четырнадцать", " пятнадцать", " шестнадцать", " семнадцать", " восемнадцать", " девятнадцать")
razryad = Array("", " тысяч", " миллион", " миллиард", " триллион", " квадриллион", " квинтиллион")
Dim t, o '// десятки '// единицы
result = hundreds(num \ 100)
If num = 0 Then Exit Function
t = (num Mod 100) \ 10
o = num Mod 10
If t <> 1 Then
result = result + tens(t)
Select Case o
Case 1
If razr = 1 Then
result = result + " одна"
Else
result = result + " один"
End If
Case 2
If razr = 1 Then
result = result + " две"
Else
result = result + " два"
End If
Case 3, 4, 5, 6, 7, 8, 9
result = result + ones(o)
End Select
result = result + razryad(razr)
Select Case o
Case 1
If razr = 1 Then
result = result + "а"
Case 2, 3, 4
If razr = 1 Then
result = result + "и"
Else
If (razr > 1) Then
result = result + "а"
End If
Case
Else
If (razr > 1) Then
result = result + "ов"
End Select
Else result = result + ones(num Mod 100)
result = result + razryad(razr)
If razr > 1 Then
result = result + "ов"
End If
ShortNum = result
End Function
Public Function IntToWords(s)
Dim i, count
If (Len(s) <= 0) Or (s = "0") Then
IntToWords = "ноль"
Exit Function
End If
count = (Len(s) + 2) \ 3
If count > 7 Then
IntToWords = "Value is too large"
Exit Function
End If
result = "" s = "00" + s
For i = 1 To count
result = ShortNum((Mid(s, Len(s) - 3 * i + 1, 3)), i - 1) + result
Next
If Len(result) > 0 Then
result = Right(result, Len(result) - 1)
IntToWords = result
End Function
Применение:
Private Sub Form_Load()
w$ = 271 'Входное число
me.caption = IntToWords(w$) ' Выход текста
End Sub
|