Как конвертировать числа в написанное прописью?
От: olesechka  
Дата: 13.08.06 15:53
Оценка:
Здравствуйте, Я пытаюсь найти способ, как с помощью VB создать фунцию по конвертации чисел в напичанное прописью. Я нашла на сайте Microsoft функцию в долларах/центах,
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q213360

Пыталась преобразовать в русский вариант, но не знаю, как учесть все склонения.
Буду благодарна за любой совет. В данном варианте использовала транслит, так как на домашнем компе не раскодировало русский язык.

Option Explicit
'Main Function
Function Spellnumber(ByVal MyNumber)
    Dim Rubli, Kopeiki, Temp
    Dim DecimalPlace, Count
    ReDim Place(9) As String
    Place(2) = " Tyshcha "
    Place(3) = " Million "
    Place(4) = " Milliard "
    Place(5) = " Trillion "
    ' String representation of amount.
    MyNumber = Trim(Str(MyNumber))
    ' Position of decimal place 0 if none.
    DecimalPlace = InStr(MyNumber, ".")
    ' Convert Kopeiki and set MyNumber to Rubl' amount.
    If DecimalPlace > 0 Then
        Kopeiki = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
                  "00", 2))
        MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If
    Count = 1
    Do While MyNumber <> ""
        Temp = GetHundreds(Right(MyNumber, 3))
        If Temp <> "" Then Rubli = Temp & Place(Count) & Rubli
        If Len(MyNumber) > 3 Then
            MyNumber = Left(MyNumber, Len(MyNumber) - 3)
        Else
            MyNumber = ""
        End If
        Count = Count + 1
    Loop
    Select Case Rubli
        Case ""
            Rubli = "Nol' Rublei"
        Case "One"
            Rubli = "Odin Rubl'"
         Case Else
            Rubli = Rubli & " Rubli"
    End Select
    Select Case Kopeiki
        Case ""
            Kopeiki = " i Nol' Êîïååê"
        Case "One"
            Kopeiki = " i Odna Kopeika"
              Case Else
            Kopeiki = " i " & Kopeiki & " Kopeiki"
    End Select
    Spellnumber = Rubli & Kopeiki
End Function
      
' Converts a number from 100-999 into text
Function GetHundreds(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    ' Convert the hundreds place.
    If Mid(MyNumber, 1, 1) <> "0" Then
        Result = GetDigit(Mid(MyNumber, 1, 1)) & " Sto "
    End If
    ' Convert the tens and ones place.
    If Mid(MyNumber, 2, 1) <> "0" Then
        Result = Result & GetTens(Mid(MyNumber, 2))
    Else
        Result = Result & GetDigit(Mid(MyNumber, 3))
    End If
    GetHundreds = Result
End Function
      
' Converts a number from 10 to 99 into text.
Function GetTens(TensText)
    Dim Result As String
    Result = ""           ' Null out the temporary function value.
    If Val(Left(TensText, 1)) = 1 Then   ' If value between 10-19...
        Select Case Val(TensText)
            Case 10: Result = "Desyat'"
            Case 11: Result = "Odinnadtzat'"
            Case 12: Result = "Dvenadtzat'"
            Case 13: Result = "Trinadtzat'"
            Case 14: Result = "Chetyrnadtzat'"
            Case 15: Result = "Pyatnadtzat'"
            Case 16: Result = "Shestnadtzat'"
            Case 17: Result = "Semnadtzat'"
            Case 18: Result = "Vosemnadtzat'"
            Case 19: Result = "Devyatnadtzat'"
            Case Else
        End Select
    Else                                 ' If value between 20-99...
        Select Case Val(Left(TensText, 1))
            Case 2: Result = "Dvadtzat' "
            Case 3: Result = "Tridtzat' "
            Case 4: Result = "Sorok "
            Case 5: Result = "Pyat'desyat "
            Case 6: Result = "Shest'desyat "
            Case 7: Result = "Sem'desyat "
            Case 8: Result = "Vosem'desyat "
            Case 9: Result = "Devyanosto "
            Case Else
        End Select
        Result = Result & GetDigit _
            (Right(TensText, 1))  ' Retrieve ones place.
    End If
    GetTens = Result
End Function
     
' Converts a number from 1 to 9 into text.
Function GetDigit(Digit)
    Select Case Val(Digit)
        Case 1: GetDigit = "Odin"
        Case 2: GetDigit = "Dva"
        Case 3: GetDigit = "Tri"
        Case 4: GetDigit = "Chetyre"
        Case 5: GetDigit = "Pyat'"
        Case 6: GetDigit = "Shest'"
        Case 7: GetDigit = "Sem'"
        Case 8: GetDigit = "Vosem'"
        Case 9: GetDigit = "Devyat'"
        Case Else: GetDigit = ""
    End Select
End Function


Спасибо.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.