Thread: Function not returning value View Single Post
 civa Authorized User Join Date: Jan 2005 Location: , , . Posts: 15 Thanks: 0 Thanked 0 Times in 0 Posts Function not returning value

Function which I wrote for convertion of numbers to words is not returning the value. Please help me on this as I am new to Access vba.

Function GetWords(ByVal Amt As Currency) As String
Dim S(27) As String
Dim MW(7) As String
Dim Words As String
Dim AndFlg As Boolean
Dim Mno As String
Dim Pno As String
Dim J As Integer
S(1) = " One"
S(2) = " Two"
S(3) = " Three"
S(4) = " Four"
S(5) = " Five"
S(6) = " Six"
S(7) = " Seven"
S(8) = " Eight"
S(9) = " Nine"
S(10) = " Ten"
S(11) = " Eleven"
S(12) = " Twelve"
S(13) = " Thirteen"
S(14) = " Fourteen"
S(15) = " Fifteen"
S(16) = " Sixteen"
S(17) = " Seventeen"
S(18) = " Eighteen"
S(19) = " Nineteen"
S(20) = " Twenty"
S(21) = " Thirty"
S(22) = " Forty"
S(23) = " Fifty"
S(24) = " Sixty"
S(25) = " Seventy"
S(26) = " Eighty"
S(27) = " Ninety"

MW(1) = " Hundred"
MW(2) = " Crore"
MW(3) = " Lakhs"
MW(4) = " Thousand"
MW(5) = " Hundred"
MW(6) = ""
MW(7) = " Paise"
Words = ""
Pno = Str(Int(Amt)) + Mid(Str(Amt), Len(Str(Amt)) - 1, 2)
AndFlg = False
For J = 7 To 1 Step -1
Mno = Val(IIf(J = 1 Or J = 5, Mid(Pno, Len(Pno), 1), Mid(Pno, Len(Pno) - 1, 2)))
Select Case (Mno)
Case Is = 0
Words = S(Mno) & MW(J) & Words
Case Is <= 20
Words = S(18 + Int(Mno / 10)) & IIf(Mno Mod 10 > 0, S(Mno Mod 10), "") & MW(J) & Words
End Select
If Not AndFlg And Words <> "" And (Amt > 99 Or (Amt - Int(Amt) > 0 And Amt > 0.99)) Then
If (Amt Mod 100) <> 0 Then
Words = " and" & Words
AndFlg = True
End If
End If
Pno = Mid(Pno, 1, Len(Pno) - IIf(J = 1 Or J = 5, 1, 2))
If Len(Trim(Pno)) = 0 Then
Exit Function
End If
Next
GetWords = Words

End Function

help me.