RDLC Indian Currency to Words Conversion

时间:2017-12-18 05:21:55

标签: vba excel-vba rdlc currency-formatting excel

The below described function is used for the conversion of AMOUNT to WORDS in RDLC :

 Function RupeesToWord(ByVal MyNumber)
    Dim Temp
    Dim Rupees, Paisa As String
    Dim DecimalPlace, iCount
    Dim Hundreds, Words As String
    Dim place(9) As String
    place(0) = " Thousand "
    place(2) = " Lakh "
    place(4) = " Crore "
    place(6) = " Arab "
    place(8) = " Kharab "

    On Error Resume Next

    ' Convert MyNumber to a string, trimming extra spaces.
    MyNumber = Trim(Str(MyNumber))

    ' Find decimal place.
    DecimalPlace = InStr(MyNumber, ".")

    ' If we find decimal place...
    If DecimalPlace > 0 Then
        ' Convert Paisa
        Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
        If Temp > 0 Then
            Paisa = " and " & ConvertTens(Temp) & " Paisa"
        End If

    '  Strip off paisa from remainder to convert.
       MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If

    '===============================================================
    Dim TM As String ' If MyNumber between Rs.1 To 99 Only.
    TM = Right(MyNumber, 2)

    If Len(MyNumber) > 0 And Len(MyNumber) <= 2 Then
        If Len(TM) = 1 Then
            Words = ConvertDigit(TM)
            RupeesToWord = "Rupees " & Words & Paisa & " Only"
            Exit Function
        Else
            If Len(TM) = 2 Then
                Words = ConvertTens(TM)
                RupeesToWord = "Rupees " & Words & Paisa & " Only"
                Exit Function
            End If
        End If
    End If
    '===============================================================

    ' Convert last 3 digits of MyNumber to ruppees in word.
    Hundreds = ConvertHundreds(Right(MyNumber, 3))
    ' Strip off last three digits
    MyNumber = Left(MyNumber, Len(MyNumber) - 3)

    iCount = 0
    Do While MyNumber <> ""
        'Strip last two digits
        Temp = Right(MyNumber, 2)
        If Len(MyNumber) = 1 Then
            If Trim(Words) = "Thousand" _
              Or Trim(Words) = "Lakh Thousand" _
              Or Trim(Words) = "Lakh" _
              Or Trim(Words) = "Crore" _
              Or Trim(Words) = "Crore Lakh Thousand" _
              Or Trim(Words) = "Arab Crore Lakh Thousand" _
              Or Trim(Words) = "Arab" _
              Or Trim(Words) = "Kharab Arab Crore Lakh Thousand" _
              Or Trim(Words) = "Kharab" _
            Then
                Words = ConvertDigit(Temp) & place(iCount)
            MyNumber = Left(MyNumber, Len(MyNumber) - 1)
                Else
                Words = ConvertDigit(Temp) & place(iCount) & Words
                MyNumber = Left(MyNumber, Len(MyNumber) - 1)
            End If
        Else
            If Trim(Words) = "Thousand" _
              Or Trim(Words) = "Lakh Thousand" _
              Or Trim(Words) = "Lakh" _
              Or Trim(Words) = "Crore" _
              Or Trim(Words) = "Crore Lakh Thousand" _
              Or Trim(Words) = "Arab Crore Lakh Thousand" _
              Or Trim(Words) = "Arab" _
            Then
                Words = ConvertTens(Temp) & place(iCount)
                MyNumber = Left(MyNumber, Len(MyNumber) - 2)
            Else
                '=================================================================
                ' if only Lakh, Crore, Arab, Kharab

                If Trim(ConvertTens(Temp) & place(iCount)) = "Lakh" _
                  Or Trim(ConvertTens(Temp) & place(iCount)) = "Crore" _
                  Or Trim(ConvertTens(Temp) & place(iCount)) = "Arab" _
                Then
                    Words = Words
                    MyNumber = Left(MyNumber, Len(MyNumber) - 2)
                Else
                    Words = ConvertTens(Temp) & place(iCount) & Words
                    MyNumber = Left(MyNumber, Len(MyNumber) - 2)
                End If
            End If
        End If
        iCount = iCount + 2
    RupeesToWord = "Rupees " & Words & Hundreds & Paisa & " Only"
End Function

I used above code to get the result, the one that I'm looking for is like, "One Lakh Twenty Five Thousand And Thirty Seven Rupees Only" Is there any way to get the required result, help me out of this?**

0 个答案:

没有答案