VB Code:
Private Sub Command1_Click()
'*** Usage ***
MsgBox AmountToWords(InputBox("Enter Amount:"))
End Sub
Private Function AmountToWords(ByVal num As Double)
Dim s As String, sa() As String
'Rupees part
s = Int(num)
s = Format(s, "-##-##-##-##-##-#-##")
Do While InStr(s, "--") > 0
s = Replace(s, "--", "-") 'remove extra seperators
Loop
If s = "-" Then
AmountToWords = "Rupees Zero"
Else
sa = Split(s, "-")
For i = UBound(sa) To 1 Step -1
AmountToWords = GetNum(sa(i)) & GetPlace(sa(i), UBound(sa) - i + 1) & AmountToWords
Next
AmountToWords = "Rupees " & AmountToWords
End If
'Paise Part
If Int(num) <> num Then
s = Format(num, "0.00")
s = Mid(s, InStr(s, ".") + 1, 2)
AmountToWords = AmountToWords & " and " & GetNum(s) & " paise"
End If
AmountToWords = AmountToWords & " only"
End Function
Private Function GetNum(ByVal num As Long) As String
Select Case num
Case 0
' GetNum = "zero"
Case Is < 11
GetNum = Choose(num, "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten")
Case Is < 20
GetNum = Choose(num - 10, "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen")
Case Is < 100
GetNum = Choose(num \ 10, "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety")
GetNum = GetNum & " " & GetNum(num Mod 10)
End Select
End Function
Private Function GetPlace(ByVal num As Long, ByVal nPlace As Long) As String
If num > 0 Then GetPlace = Choose(nPlace, "", " hundred ", " thousand ", " lakh ", " crore ", " million ", " billion ", " trillion ")
End Function