REM ***** BASIC *****
Option Explicit
Sub Main
Print getAmountInWords("999999999.99")
End Sub
'********************************************************************************************************
'Function Name : getAmountInWords
'Description : To convert the Amount value into words(formatted as "000000000.00")
' (Maximum allowed limit 999999999.99)
'Input Parameters : Amount
'Returns : String
'Creat by : Sanjeev Meher on 9th Feb 2013
'Specific Logic used: None
'********************************************************************************************************
Public Function getAmountInWords(strAmount As String) As String
Dim strIntPart As String
Dim strDecPart As String
Dim strCroresPart As String
Dim strLakhsPart As String
Dim strThousandsPart As String
Dim strHundredsPart As String
Dim strTensPart As String
Dim strOnesPart As String
Dim strDecTensPart As String
Dim strDecOnesPart As String
Dim strAmtWords As String
Dim dblIntPart As Double
Dim intDecPart As Integer
Dim strDecWords As String
Dim iErr As Integer
'handle for typemismatch error
'??Err.Clear
'??On Error Resume Next
On Error Goto BadError
strAmount = CDbl(strAmount)
'??If Err.Number = "13" Then
'?? getAmountInWords = ""
'?? Exit Function
'??End If
'??Err.Clear
strAmount = Format(Trim(strAmount), "000000000.00")
'if the value is negative,zero above the limit then give error message
If Val(strAmount) < 0 Then
getAmountInWords = ""
Exit Function
ElseIf Val(strAmount) = 0 Then
getAmountInWords = "Rupees Zero"
Exit Function
ElseIf Val(strAmount) > 999999999.99 Then
getAmountInWords = ""
Exit Function
End If
'store the integer and decimal parts separately
strIntPart = Mid(strAmount, 1, 9)
strDecPart = Mid(strAmount, 11, 2)
'store the individual places in variables
strCroresPart = Mid(strIntPart, 1, 2)
strLakhsPart = Mid(strIntPart, 3, 2)
strThousandsPart = Mid(strIntPart, 5, 2)
strHundredsPart = Mid(strIntPart, 7, 1)
strTensPart = Mid(strIntPart, 8, 1)
strOnesPart = Mid(strIntPart, 9, 1)
strDecTensPart = Mid(strDecPart, 1, 1)
strDecOnesPart = Mid(strDecPart, 2, 1)
strAmtWords = ""
'To make the Crores Part
If Val(strCroresPart) <> 0 Then
strAmtWords = strAmtWords & getCroresPart(strCroresPart)
End If
'To make the Lakhs Part
If Val(strLakhsPart) <> 0 Then
strAmtWords = strAmtWords & getLakhsPart(strLakhsPart)
End If
'To make the Thousands Part
If Val(strThousandsPart) <> 0 Then
strAmtWords = strAmtWords & getThousandsPart(strThousandsPart)
End If
'To make the hundreds Part
If Val(strHundredsPart) <> 0 Then
strAmtWords = strAmtWords & getOnesColumn(Format(strHundredsPart, "00")) & " Hundred "
End If
'To make Tens and Ones part
If Val(strTensPart & strOnesPart) <> 0 And Val(strAmount) > 100 Then
strAmtWords = strAmtWords & "and " & getTensOnesPart(strAmount, strTensPart, strOnesPart)
Else
strAmtWords = strAmtWords & getTensOnesPart(strAmount, strTensPart, strOnesPart)
End If
strDecWords = ""
'To make Tens and Ones part in the decimal part
If Val(strDecTensPart & strDecOnesPart) <> 0 Then
strDecWords = strDecWords & getTensOnesPart(Val(strAmount), strDecTensPart, strDecOnesPart)
End If
'If both integer and decimal part are not Zero then add Rupees and Paise only
If Val ...
(more)