VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This Function Retrives the String Like(Ex:if you give 123456789.35 then it returns THELVE CROES TH

by Ramaiah/Satyam (1 Submission)
Category: Math/Dates
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sun 8th September 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This Function Retrives the String Like(Ex:if you give 123456789.35 then it returns "THELVE CROES THIRTY FOUR LACKS FIFTY SIX THOUSAND SEVE

API Declarations


Dim arrOrgList() As Integer, arrList(1 To 9) As Integer, arrInWords(1 To 50) As String
Dim sNumber As String, sNumber1 As String, iNumLength As Integer, iOrgListIndex As Integer
Dim iNoOfarrList As Integer, iarrListCount As Integer, iWordIndex As Integer
Dim I As Integer, bPaise As Boolean, iPaise As Integer
Dim sInWords As String, iOrgListTrack As Integer, iMaxIndex As Integer, DECP As Integer


Rate This Function Retrives the String Like(Ex:if you give 123456789.35 then it returns THELVE CROES TH



    On Error Resume Next
    If Len(LNumber) > 0 Then LNumber = CDbl(Format(LNumber, "##0.00"))    
    DECP = InStr(1, LNumber, ".", vbTextCompare)
    If DECP > 0 Then
        sNumber = Mid(LNumber, 1, InStr(1, LNumber, ".") - 1)
        sNumber1 = Mid(LNumber, InStr(1, LNumber, ".") + 1)
        bPaise = True: iNumLength = Len(sNumber)
    Else
        sNumber = Format(LNumber, "###############"): iNumLength = Len(sNumber)
    End If
Satya:
    If iNumLength = 0 Then
        InWords = ""
        Exit Function
    Else
        ReDim arrOrgList(1 To iNumLength) As Integer
    End If
    
    iOrgListIndex = 1
    Do Until (iOrgListIndex > iNumLength)
        arrOrgList(iOrgListIndex) = Mid(sNumber, iNumLength - iOrgListIndex + 1, 1)
        iOrgListIndex = iOrgListIndex + 1
    Loop
    
    iNoOfarrList = iNumLength \ 9
    If Not (iNoOfarrList * 9 = iNumLength) Then
        iNoOfarrList = iNoOfarrList + 1
    End If
    
    iarrListCount = 0: iWordIndex = 1
    Do Until (iarrListCount >= iNoOfarrList)
        If iarrListCount >= 1 Then
            arrInWords(iWordIndex) = "CRORES"
            iWordIndex = iWordIndex + 1
        End If
        If iarrListCount = (iNoOfarrList - 1) Then
            iMaxIndex = iNumLength - ((iNoOfarrList - 1) * 9)
        Else
            iMaxIndex = 9
        End If
        iOrgListTrack = 0
        For iOrgListIndex = 1 To iMaxIndex 'SizeofarrList 'UBound(arrList)
            iOrgListTrack = iOrgListTrack + 1
            arrList(iOrgListIndex) = arrOrgList(iOrgListTrack) '(iarrListCount * SizeofarrList) + iOrgListIndex)
        Next iOrgListIndex
        
        'Here in place of UBound write sizeofarrList
        For iOrgListIndex = 1 To iMaxIndex 'SizeofarrList 'UBound(arrList)
            'for units place
            If iOrgListIndex = 1 Then
                If (iMaxIndex = 1) Or Not (arrList(iOrgListIndex + 1) = 1) Then
                    Select Case arrList(iOrgListIndex)
                        Case 1: arrInWords(iWordIndex) = "ONE"
                        Case 2: arrInWords(iWordIndex) = "TWO"
                        Case 3: arrInWords(iWordIndex) = "THREE"
                        Case 4: arrInWords(iWordIndex) = "FOUR"
                        Case 5: arrInWords(iWordIndex) = "FIVE"
                        Case 6: arrInWords(iWordIndex) = "SIX"
                        Case 7: arrInWords(iWordIndex) = "SEVEN"
                        Case 8: arrInWords(iWordIndex) = "EIGHT"
                        Case 9: arrInWords(iWordIndex) = "NINE"
                    End Select
                    If (arrList(iOrgListIndex) = 0) Then
                        If iMaxIndex > 1 Then
                            arrInWords(iWordIndex) = ""
                        Else
                            arrInWords(iWordIndex) = "ZERO"
                        End If
                    End If
                Else
                    arrInWords(iWordIndex) = ""
                End If
                iWordIndex = iWordIndex + 1
            End If
            
            'for tens place
            If (iOrgListIndex = 2) Or (iOrgListIndex = 5) Or (iOrgListIndex = 7) Or (iOrgListIndex = 9) Then
                If arrList(iOrgListIndex) = 1 Then
                    Select Case arrList(iOrgListIndex - 1)
                        Case 0: arrInWords(iWordIndex) = "TEN"
                        Case 1: arrInWords(iWordIndex) = "ELEVEN"
                        Case 2: arrInWords(iWordIndex) = "TWELVE"
                        Case 3: arrInWords(iWordIndex) = "THIRTEEN"
                        Case 4: arrInWords(iWordIndex) = "FOURTEEN"
                        Case 5: arrInWords(iWordIndex) = "FIFTEEN"
                        Case 6: arrInWords(iWordIndex) = "SIXTEEN"
                        Case 7: arrInWords(iWordIndex) = "SEVENTEEN"
                        Case 8: arrInWords(iWordIndex) = "EIGHTEEN"
                        Case 9: arrInWords(iWordIndex) = "NINETEEN"
                    End Select
                    If iOrgListIndex = 5 Then
                        arrInWords(iWordIndex) = arrInWords(iWordIndex) & " THOUSAND"
                    End If
                    If iOrgListIndex = 7 Then
                        arrInWords(iWordIndex) = arrInWords(iWordIndex) & " LAKHS"
                    End If
                    If iOrgListIndex = 9 Then
                        arrInWords(iWordIndex) = arrInWords(iWordIndex) & " CRORES"
                    End If
                Else
                    Select Case arrList(iOrgListIndex)
                        Case 0: arrInWords(iWordIndex) = "": If InStr(1, arrInWords(iWordIndex - 1), " ") = 0 And iWordIndex > 4 Then arrInWords(iWordIndex - 1) = ""
                        Case 2: arrInWords(iWordIndex) = "TWENTY"
                        Case 3: arrInWords(iWordIndex) = "THIRTY"
                        Case 4: arrInWords(iWordIndex) = "FORTY"
                        Case 5: arrInWords(iWordIndex) = "FIFTY"
                        Case 6: arrInWords(iWordIndex) = "SIXTY"
                        Case 7: arrInWords(iWordIndex) = "SEVENTY"
                        Case 8: arrInWords(iWordIndex) = "EIGHTY"
                        Case 9: arrInWords(iWordIndex) = "NINETY"
                    End Select
                End If
                iWordIndex = iWordIndex + 1
            End If
            
            'For hundreds place
            If iOrgListIndex = 3 Then
                Select Case arrList(iOrgListIndex)
                    Case 0: arrInWords(iWordIndex) = ""
                    Case 1: arrInWords(iWordIndex) = "ONE HUNDRED"
                    Case 2: arrInWords(iWordIndex) = "TWO HUNDRED"
                    Case 3: arrInWords(iWordIndex) = "THREE HUNDRED"
                    Case 4: arrInWords(iWordIndex) = "FOUR HUNDRED"
                    Case 5: arrInWords(iWordIndex) = "FIVE HUNDRED"
                    Case 6: arrInWords(iWordIndex) = "SIX HUNDRED"
                    Case 7: arrInWords(iWordIndex) = "SEVEN HUNDRED"
                    Case 8: arrInWords(iWordIndex) = "EIGHT HUNDRED"
                    Case 9: arrInWords(iWordIndex) = "NINE HUNDRED"
                End Select
                If Not (arrList(1) = 0 And arrList(2) = 0) And Len(InStr(1, iNumber, ".")) = 0 Then
                    arrInWords(iWordIndex) = arrInWords(iWordIndex) & " AND"
                End If
                iWordIndex = iWordIndex + 1
            End If
            
            'for Thousands place
            If (iOrgListIndex = 4) Then 'And Not (arrList(iOrgListIndex + 1) = 1) Then
                If (iOrgListIndex + 1) > iMaxIndex Then
                    Select Case arrList(iOrgListIndex)
                        Case 0: arrInWords(iWordIndex) = ""
                        Case 1: arrInWords(iWordIndex) = "ONE THOUSAND"
                        Case 2: arrInWords(iWordIndex) = "TWO THOUSAND"
                        Case 3: arrInWords(iWordIndex) = "THREE THOUSAND"
                        Case 4: arrInWords(iWordIndex) = "FOUR THOUSAND"
                        Case 5: arrInWords(iWordIndex) = "FIVE THOUSAND"
                        Case 6: arrInWords(iWordIndex) = "SIX THOUSAND"
                        Case 7: arrInWords(iWordIndex) = "SEVEN THOUSAND"
                        Case 8: arrInWords(iWordIndex) = "EIGHT THOUSAND"
                        Case 9: arrInWords(iWordIndex) = "NINE THOUSAND"
                    End Select
                ElseIf Not (arrList(iOrgListIndex + 1) = 1) Then
                    Select Case arrList(iOrgListIndex)
                        Case 0: arrInWords(iWordIndex) = "THOUSAND" 'Thousand in place of null
                        Case 1: arrInWords(iWordIndex) = "ONE THOUSAND"
                        Case 2: arrInWords(iWordIndex) = "TWO THOUSAND"
                        Case 3: arrInWords(iWordIndex) = "THREE THOUSAND"
                        Case 4: arrInWords(iWordIndex) = "FOUR THOUSAND"
                        Case 5: arrInWords(iWordIndex) = "FIVE THOUSAND"
                        Case 6: arrInWords(iWordIndex) = "SIX THOUSAND"
                        Case 7: arrInWords(iWordIndex) = "SEVEN THOUSAND"
                        Case 8: arrInWords(iWordIndex) = "EIGHT THOUSAND"
                        Case 9: arrInWords(iWordIndex) = "NINE THOUSAND"
                    End Select
                End If
                iWordIndex = iWordIndex + 1
            End If
            
            'for Lakhs place
            If (iOrgListIndex = 6) Then 'And Not (arrList(iOrgListIndex + 1) = 1) Then
                If (iOrgListIndex + 1) > iMaxIndex Then
                    Select Case arrList(iOrgListIndex)
                        Case 0: arrInWords(iWordIndex) = ""
                        Case 1: arrInWords(iWordIndex) = "ONE LAKH"
                        Case 2: arrInWords(iWordIndex) = "TWO LAKHS"
                        Case 3: arrInWords(iWordIndex) = "THREE LAKHS"
                        Case 4: arrInWords(iWordIndex) = "FOUR LAKHS"
                        Case 5: arrInWords(iWordIndex) = "FIVE LAKHS"
                        Case 6: arrInWords(iWordIndex) = "SIX LAKHS"
                        Case 7: arrInWords(iWordIndex) = "SEVEN LAKHS"
                        Case 8: arrInWords(iWordIndex) = "EIGHT LAKHS"
                        Case 9: arrInWords(iWordIndex) = "NINE LAKHS"
                    End Select
                ElseIf Not (arrList(iOrgListIndex + 1) = 1) Then
                    Select Case arrList(iOrgListIndex)
                        Case 0: arrInWords(iWordIndex) = "LAKHS" 'changed here to lakhs in place of null
                        Case 1: arrInWords(iWordIndex) = "ONE LAKH"
                        Case 2: arrInWords(iWordIndex) = "TWO LAKHS"
                        Case 3: arrInWords(iWordIndex) = "THREE LAKHS"
                        Case 4: arrInWords(iWordIndex) = "FOUR LAKHS"
                        Case 5: arrInWords(iWordIndex) = "FIVE LAKHS"
                        Case 6: arrInWords(iWordIndex) = "SIX LAKHS"
                        Case 7: arrInWords(iWordIndex) = "SEVEN LAKHS"
                        Case 8: arrInWords(iWordIndex) = "EIGHT LAKHS"
                        Case 9: arrInWords(iWordIndex) = "NINE LAKHS"
                    End Select
                End If
                iWordIndex = iWordIndex + 1
            End If
            
            'for CRORES place
            If (iOrgListIndex = 8) Then 'And Not (arrList(iOrgListIndex + 1) = 1) Then
                If (iOrgListIndex + 1) > iMaxIndex Then
                    Select Case arrList(iOrgListIndex)
                        Case 0: arrInWords(iWordIndex) = ""
                        Case 1: arrInWords(iWordIndex) = "ONE CRORE"
                        Case 2: arrInWords(iWordIndex) = "TWO CRORES"
                        Case 3: arrInWords(iWordIndex) = "THREE CRORES"
                        Case 4: arrInWords(iWordIndex) = "FOUR CRORES"
                        Case 5: arrInWords(iWordIndex) = "FIVE CRORES"
                        Case 6: arrInWords(iWordIndex) = "SIX CRORES"
                        Case 7: arrInWords(iWordIndex) = "SEVEN CRORES"
                        Case 8: arrInWords(iWordIndex) = "EIGHT CRORES"
                        Case 9: arrInWords(iWordIndex) = "NINE CRORES"
                    End Select
                ElseIf Not (arrList(iOrgListIndex + 1) = 1) Then
                    Select Case arrList(iOrgListIndex)
                        Case 0: arrInWords(iWordIndex) = "CRORES" 'changed here to lakhs in place of null
                        Case 1: arrInWords(iWordIndex) = "ONE CRORE"
                        Case 2: arrInWords(iWordIndex) = "TWO CRORES"
                        Case 3: arrInWords(iWordIndex) = "THREE CRORES"
                        Case 4: arrInWords(iWordIndex) = "FOUR CRORES"
                        Case 5: arrInWords(iWordIndex) = "FIVE CRORES"
                        Case 6: arrInWords(iWordIndex) = "SIX CRORES"
                        Case 7: arrInWords(iWordIndex) = "SEVEN CRORES"
                        Case 8: arrInWords(iWordIndex) = "EIGHT CRORES"
                        Case 9: arrInWords(iWordIndex) = "NINE CRORES"
                    End Select
                End If
                iWordIndex = iWordIndex + 1
            End If
        Next iOrgListIndex
        iarrListCount = iarrListCount + 1
    Loop
    I = iWordIndex - 1
    sInWords = ""
    Do Until (I = 0)
        If Trim(arrInWords(I)) <> "" Then
            sInWords = sInWords & Trim(arrInWords(I)) & " "
        End If
        I = I - 1
    Loop
    If bPaise = True Then
        iPaise = iPaise + 1
        If iPaise = 1 Then
            sNumber = sNumber1: iNumLength = 2: sInwords1 = sInWords: sInWords = ""
            GoTo Satya
        End If
        If Val(Mid(LNumber, 1, InStr(1, LNumber, ".") - 1)) > 1 Then
            InWords = StrConv(Trim(sInwords1) & " Rupees And " & Trim(sInWords) & " Paise Only", vbProperCase)
        Else
            InWords = StrConv(Trim(sInwords1) & " Rupee And " & Trim(sInWords) & " Paise Only", vbProperCase)
        End If
    ElseIf Val(sNumber) > 1 Then
        InWords = StrConv(Trim(sInWords), vbProperCase) & " Rupees Only"
    Else
        InWords = StrConv(Trim(sInWords), vbProperCase) & " Rupee Only"
    End If
End Function


Download this snippet    Add to My Saved Code

This Function Retrives the String Like(Ex:if you give 123456789.35 then it returns THELVE CROES TH Comments

No comments have been posted about This Function Retrives the String Like(Ex:if you give 123456789.35 then it returns THELVE CROES TH. Why not be the first to post a comment about This Function Retrives the String Like(Ex:if you give 123456789.35 then it returns THELVE CROES TH.

Post your comment

Subject:
Message:
0/1000 characters