Visual Basic Цифры - прописью, Помогите избавиться от "рублей" - VB

Узнай цену своей работы

Формулировка задачи:

Помогите пожалуйста избавиться от "рублей и копеек"
Нужно только описание цифр, (пример: 345 - тристо сорок пять)
Function ПРОПИСЬЮ(SourceDigits As Currency) As String
Dim STRNG As String, CHAR, Result As String, Prom As String
Dim i, STRNG_len As Long
Dim SourceDigTail As Currency
SourceDigTail = (SourceDigits - Int(SourceDigits)) * 100
SourceDigits = Int(SourceDigits)
STRNG = SourceDigits
STRNG_len = Len(STRNG)
For i = 1 To 9 - STRNG_len Step 1
STRNG = "0" & STRNG
Next i
For i = 9 To 9 - STRNG_len + 1 Step -1
CHAR = Mid(STRNG, i, 1)
If CHAR = "" Then GoTo end_c
If i = 2 Or i = 5 Or i = 8 Then
If CHAR = "1" Then
CHAR = Mid(STRNG, i, 2)
Select Case CHAR
Case "10"
Prom = "десять "
Case "11"
Prom = "одиннадцать "
Case "12"
Prom = "двенадцать "
Case "13"
Prom = "тринадцать "
Case "14"
Prom = "четырнадцать "
Case "15"
Prom = "пятнадцать "
Case "16"
Prom = "шестнадцать "
Case "17"
Prom = "семьнадцать "
Case "18"
Prom = "восемьнадцать "
Case "19"
Prom = "девятнадцать "
End Select
Else ' If char Not = 1
Select Case CHAR
Case "0"
Prom = ""
Case "2"
Prom = "двадцать "
Case "3"
Prom = "тридцать "
Case "4"
Prom = "сорок "
Case "5"
Prom = "пятьдесят "
Case "6"
Prom = "шестьдесят "
Case "7"
Prom = "семьдесят "
Case "8"
Prom = "восемьдесят "
Case "9"
Prom = "девяносто "
End Select
End If
End If
If i = 1 Or i = 4 Or i = 7 Then
Select Case CHAR
Case "0"
Prom = ""
Case "1"
Prom = "сто "
Case "2"
Prom = "двести "
Case "3"
Prom = "триста "
Case "4"
Prom = "четыреста "
Case "5"
Prom = "пятьсот "
Case "6"
Prom = "шестьсот "
Case "7"
Prom = "семьсот "
Case "8"
Prom = "восемьсот "
Case "9"
Prom = "девятьсот "
End Select
End If
If i = 3 Or i = 6 Or i = 9 Then
If i = 9 And Mid(STRNG, i - 1, 1) = "1" Then
Result = "рублей " & Result
GoTo end_c
End If
If i = 3 And Mid(STRNG, i - 1, 1) = "1" Then
Result = "миллионов " & Result
GoTo end_c
End If
If i = 6 And Mid(STRNG, i - 1, 1) = "1" Then
Result = "тысяч " & Result
GoTo end_c
End If
Select Case CHAR
Case "0"
Prom = ""
Case "1"
If i = 6 Then
Prom = "одна "
Else
Prom = "один "
End If
Case "2"
If i = 6 Then
Prom = "две "
Else
Prom = "два "
End If
Case "3"
Prom = "три "
Case "4"
Prom = "четыре "
Case "5"
Prom = "пять "
Case "6"
Prom = "шесть "
Case "7"
Prom = "семь "
Case "8"
Prom = "восемь "
Case "9"
Prom = "девять "
End Select
End If
Select Case i
Case 3
Select Case CHAR
Case "1"
Result = "миллион " & Result
Case "2", "3", "4"
Result = "миллиона " & Result
Case "5", "6", "7", "8", "9"
Result = "миллионов " & Result
Case "0"
If STRNG_len > 6 Then
Result = "миллионов " & Result
End If
End Select
Case 6
Select Case CHAR
Case "1"
Result = "тысячa " & Result
Case "2", "3", "4"
Result = "тысячи " & Result
Case "5", "6", "7", "8", "9"
Result = "тысяч " & Result
Case "0"
If STRNG_len > 3 Then
Result = "тысяч " & Result
End If
End Select
Case 9
Select Case CHAR
Case "1"
Result = "рубль " & Result
Case "2", "3", "4"
Result = "рубля " & Result
Case "0", "5", "6", "7", "8", "9"
Result = "рублей " & Result
End Select
End Select
Result = Prom & Result
end_c:
Next i
Result = Format(Mid(Result, 1, 1), ">") & Mid(Result, 2)
ПРОПИСЬЮ = Result & Format(SourceDigTail, "00") & " коп."
End Function

Решение задачи: «Visual Basic Цифры - прописью, Помогите избавиться от "рублей"»

textual
Листинг программы
<font color="blue">Public</font> <font color="blue">Function</font> Propis(SourceDigits <font color="blue">As</font> <font color="blue">Long</font>) <font color="blue">As</font> <font color="blue">String</font>
    <font color="blue">Dim</font> STRNG <font color="blue">As</font> <font color="blue">String</font>, <font color="blue">CHAR</font>, Result <font color="blue">As</font> <font color="blue">String</font>, Prom <font color="blue">As</font> <font color="blue">String</font>
    <font color="blue">Dim</font> i, STRNG_len <font color="blue">As</font> <font color="blue">Long</font>


    STRNG = SourceDigits
    STRNG_len = Len(STRNG)
    <font color="blue">For</font> i = <font color="darkblue"><b>1</b></font> <font color="blue">To</font> <font color="darkblue"><b>9</b></font> - STRNG_len <font color="blue">Step</font> <font color="darkblue"><b>1</b></font>
        STRNG = <font color="teal">"0"</font> & STRNG
    <font color="blue">Next</font> i

    <font color="blue">For</font> i = <font color="darkblue"><b>9</b></font> <font color="blue">To</font> <font color="darkblue"><b>9</b></font> - STRNG_len + <font color="darkblue"><b>1</b></font> <font color="blue">Step</font> -<font color="darkblue"><b>1</b></font>
    <font color="blue">CHAR</font> = <font color="blue">Mid</font>(STRNG, i, <font color="darkblue"><b>1</b></font>)
    <font color="blue">If</font> <font color="blue">CHAR</font> = <font color="teal">""</font> <font color="blue">Then</font> <font color="blue">GoTo</font> end_c

    <font color="blue">If</font> i = <font color="darkblue"><b>2</b></font> <font color="blue">Or</font> i = <font color="darkblue"><b>5</b></font> <font color="blue">Or</font> i = <font color="darkblue"><b>8</b></font> <font color="blue">Then</font>
        <font color="blue">If</font> <font color="blue">CHAR</font> = <font color="teal">"1"</font> <font color="blue">Then</font>
            <font color="blue">CHAR</font> = <font color="blue">Mid</font>(STRNG, i, <font color="darkblue"><b>2</b></font>)
            <font color="blue">Select</font> <font color="blue">Case</font> <font color="blue">CHAR</font>
                <font color="blue">Case</font> <font color="teal">"10"</font>
                    Prom = <font color="teal">"десять "</font>
                <font color="blue">Case</font> <font color="teal">"11"</font>
                    Prom = <font color="teal">"одиннадцать "</font>
                <font color="blue">Case</font> <font color="teal">"12"</font>
                    Prom = <font color="teal">"двенадцать "</font>
                <font color="blue">Case</font> <font color="teal">"13"</font>
                    Prom = <font color="teal">"тринадцать "</font>
                <font color="blue">Case</font> <font color="teal">"14"</font>
                    Prom = <font color="teal">"четырнадцать "</font>
                <font color="blue">Case</font> <font color="teal">"15"</font>
                    Prom = <font color="teal">"пятнадцать "</font>
                <font color="blue">Case</font> <font color="teal">"16"</font>
                    Prom = <font color="teal">"шестнадцать "</font>
                <font color="blue">Case</font> <font color="teal">"17"</font>
                    Prom = <font color="teal">"семьнадцать "</font>
                <font color="blue">Case</font> <font color="teal">"18"</font>
                    Prom = <font color="teal">"восемьнадцать "</font>
                <font color="blue">Case</font> <font color="teal">"19"</font>
                    Prom = <font color="teal">"девятнадцать "</font>
            <font color="blue">End</font> <font color="blue">Select</font>
        <font color="blue">Else</font>
            <font color="blue">Select</font> <font color="blue">Case</font> <font color="blue">CHAR</font>
                <font color="blue">Case</font> <font color="teal">"0"</font>
                    Prom = <font color="teal">""</font>
                <font color="blue">Case</font> <font color="teal">"2"</font>
                    Prom = <font color="teal">"двадцать "</font>
                <font color="blue">Case</font> <font color="teal">"3"</font>
                    Prom = <font color="teal">"тридцать "</font>
                <font color="blue">Case</font> <font color="teal">"4"</font>
                    Prom = <font color="teal">"сорок "</font>
                <font color="blue">Case</font> <font color="teal">"5"</font>
                    Prom = <font color="teal">"пятьдесят "</font>
                <font color="blue">Case</font> <font color="teal">"6"</font>
                    Prom = <font color="teal">"шестьдесят "</font>
                <font color="blue">Case</font> <font color="teal">"7"</font>
                    Prom = <font color="teal">"семьдесят "</font>
                <font color="blue">Case</font> <font color="teal">"8"</font>
                    Prom = <font color="teal">"восемьдесят "</font>
                <font color="blue">Case</font> <font color="teal">"9"</font>
                    Prom = <font color="teal">"девяносто "</font>
            <font color="blue">End</font> <font color="blue">Select</font>
        <font color="blue">End</font> <font color="blue">If</font>
    <font color="blue">End</font> <font color="blue">If</font>
    <font color="blue">If</font> i = <font color="darkblue"><b>1</b></font> <font color="blue">Or</font> i = <font color="darkblue"><b>4</b></font> <font color="blue">Or</font> i = <font color="darkblue"><b>7</b></font> <font color="blue">Then</font>
        <font color="blue">Select</font> <font color="blue">Case</font> <font color="blue">CHAR</font>
            <font color="blue">Case</font> <font color="teal">"0"</font>
                Prom = <font color="teal">""</font>
            <font color="blue">Case</font> <font color="teal">"1"</font>
                Prom = <font color="teal">"сто "</font>
            <font color="blue">Case</font> <font color="teal">"2"</font>
                Prom = <font color="teal">"двести "</font>
            <font color="blue">Case</font> <font color="teal">"3"</font>
                Prom = <font color="teal">"триста "</font>
            <font color="blue">Case</font> <font color="teal">"4"</font>
                Prom = <font color="teal">"четыреста "</font>
            <font color="blue">Case</font> <font color="teal">"5"</font>
                Prom = <font color="teal">"пятьсот "</font>
            <font color="blue">Case</font> <font color="teal">"6"</font>
                Prom = <font color="teal">"шестьсот "</font>
            <font color="blue">Case</font> <font color="teal">"7"</font>
                Prom = <font color="teal">"семьсот "</font>
            <font color="blue">Case</font> <font color="teal">"8"</font>
                Prom = <font color="teal">"восемьсот "</font>
            <font color="blue">Case</font> <font color="teal">"9"</font>
                Prom = <font color="teal">"девятьсот "</font>
        <font color="blue">End</font> <font color="blue">Select</font>
    <font color="blue">End</font> <font color="blue">If</font>

    <font color="blue">If</font> i = <font color="darkblue"><b>3</b></font> <font color="blue">Or</font> i = <font color="darkblue"><b>6</b></font> <font color="blue">Or</font> i = <font color="darkblue"><b>9</b></font> <font color="blue">Then</font>
        <font color="blue">If</font> i = <font color="darkblue"><b>3</b></font> <font color="blue">And</font> <font color="blue">Mid</font>(STRNG, i - <font color="darkblue"><b>1</b></font>, <font color="darkblue"><b>1</b></font>) = <font color="teal">"1"</font> <font color="blue">Then</font>
            Result = <font color="teal">"миллионов "</font> & Result
            <font color="blue">GoTo</font> end_c
        <font color="blue">End</font> <font color="blue">If</font>

        <font color="blue">If</font> i = <font color="darkblue"><b>6</b></font> <font color="blue">And</font> <font color="blue">Mid</font>(STRNG, i - <font color="darkblue"><b>1</b></font>, <font color="darkblue"><b>1</b></font>) = <font color="teal">"1"</font> <font color="blue">Then</font>
            Result = <font color="teal">"тысяч "</font> & Result
            <font color="blue">GoTo</font> end_c
        <font color="blue">End</font> <font color="blue">If</font>

        <font color="blue">Select</font> <font color="blue">Case</font> <font color="blue">CHAR</font>
            <font color="blue">Case</font> <font color="teal">"0"</font>
                Prom = <font color="teal">""</font>
                <font color="blue">Case</font> <font color="teal">"1"</font>
                    <font color="blue">If</font> i = <font color="darkblue"><b>6</b></font> <font color="blue">Then</font>
                        Prom = <font color="teal">"одна "</font>
                    <font color="blue">Else</font>
                        Prom = <font color="teal">"один "</font>
                    <font color="blue">End</font> <font color="blue">If</font>
                <font color="blue">Case</font> <font color="teal">"2"</font>
                    <font color="blue">If</font> i = <font color="darkblue"><b>6</b></font> <font color="blue">Then</font>
                        Prom = <font color="teal">"две "</font>
                    <font color="blue">Else</font>
                        Prom = <font color="teal">"два "</font>
                    <font color="blue">End</font> <font color="blue">If</font>
                <font color="blue">Case</font> <font color="teal">"3"</font>
                    Prom = <font color="teal">"три "</font>
                <font color="blue">Case</font> <font color="teal">"4"</font>
                    Prom = <font color="teal">"четыре "</font>
                <font color="blue">Case</font> <font color="teal">"5"</font>
                    Prom = <font color="teal">"пять "</font>
                <font color="blue">Case</font> <font color="teal">"6"</font>
                    Prom = <font color="teal">"шесть "</font>
                <font color="blue">Case</font> <font color="teal">"7"</font>
                    Prom = <font color="teal">"семь "</font>
                <font color="blue">Case</font> <font color="teal">"8"</font>
                    Prom = <font color="teal">"восемь "</font>
                <font color="blue">Case</font> <font color="teal">"9"</font>
                    Prom = <font color="teal">"девять "</font>
            <font color="blue">End</font> <font color="blue">Select</font>
    <font color="blue">End</font> <font color="blue">If</font>
    <font color="blue">Select</font> <font color="blue">Case</font> i
        <font color="blue">Case</font> <font color="darkblue"><b>3</b></font>
            <font color="blue">Select</font> <font color="blue">Case</font> <font color="blue">CHAR</font>
                <font color="blue">Case</font> <font color="teal">"1"</font>
                    Result = <font color="teal">"миллион "</font> & Result
                <font color="blue">Case</font> <font color="teal">"2"</font>, <font color="teal">"3"</font>, <font color="teal">"4"</font>
                    Result = <font color="teal">"миллиона "</font> & Result
                <font color="blue">Case</font> <font color="teal">"5"</font>, <font color="teal">"6"</font>, <font color="teal">"7"</font>, <font color="teal">"8"</font>, <font color="teal">"9"</font>
                    Result = <font color="teal">"миллионов "</font> & Result
                <font color="blue">Case</font> <font color="teal">"0"</font>
                    <font color="blue">If</font> STRNG_len > <font color="darkblue"><b>6</b></font> <font color="blue">Then</font>
                        Result = <font color="teal">"миллионов "</font> & Result
                    <font color="blue">End</font> <font color="blue">If</font>
            <font color="blue">End</font> <font color="blue">Select</font>
        <font color="blue">Case</font> <font color="darkblue"><b>6</b></font>
            <font color="blue">Select</font> <font color="blue">Case</font> <font color="blue">CHAR</font>
                <font color="blue">Case</font> <font color="teal">"1"</font>
                    Result = <font color="teal">"тысячa "</font> & Result
                <font color="blue">Case</font> <font color="teal">"2"</font>, <font color="teal">"3"</font>, <font color="teal">"4"</font>
                    Result = <font color="teal">"тысячи "</font> & Result
                <font color="blue">Case</font> <font color="teal">"5"</font>, <font color="teal">"6"</font>, <font color="teal">"7"</font>, <font color="teal">"8"</font>, <font color="teal">"9"</font>
                    Result = <font color="teal">"тысяч "</font> & Result
                <font color="blue">Case</font> <font color="teal">"0"</font>
                    <font color="blue">If</font> STRNG_len > <font color="darkblue"><b>3</b></font> <font color="blue">Then</font>
                        Result = <font color="teal">"тысяч "</font> & Result
                    <font color="blue">End</font> <font color="blue">If</font>
            <font color="blue">End</font> <font color="blue">Select</font>
    <font color="blue">End</font> <font color="blue">Select</font>

    Result = Prom & Result

end_c:
<font color="blue">Next</font> i

    
    

    Propis = Format(<font color="blue">Mid</font>(Result, <font color="darkblue"><b>1</b></font>, <font color="darkblue"><b>1</b></font>), <font color="teal">">"</font>) & <font color="blue">Mid</font>(Result, <font color="darkblue"><b>2</b></font>)
    

<font color="blue">End</font> <font color="blue">Function</font>

ИИ поможет Вам:


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

Оцени полезность:

10   голосов , оценка 3.8 из 5
Похожие ответы