Get the best logo design for your business!

Thursday, January 12, 2012

Indian Rupee Currency - Number to Word Conversion

Let me share you my latest ms access codes that will convert word to number using the indian rupee currency. While working on this code, I found it difficult since the indian rupee currency or numeral system is unique, its different from the standard american numeral system. Anyway, to make my post short (lol), you can find the codes below.

Follow the following steps:

Step #1: Copy my ms access visual basic function below and insert it into your ms access module

Step #2: create a form in ms access with two text fields on it. Name the first text field as txtNumber and the other text field as txtInwords. Change the caption of txtNumber with Number and txtInwords with In Words

Step #3: Set the AfterUpdate Event of the txtNumber text box with this visual basic command: Me.txtInwords = convert(me.txtNumber).

You may now run your form and try.

Below is the snapshot of the program:


And lastly, the most important one, are the codes which you can find below:

Function Convert(ByVal mAmount As String, Optional Enclosed As Boolean)
Dim mDec As Variant, mDecWhat As String, mNumberOfDigits, mCntr, Word, OneD, TwoD, mInput
mInput = Format(mAmount, "####0.00")
OneD = Array("", "One ", "Two ", "Three ", "Four ", "Five ", "Six ", "Seven ", "Eight ", "Nine ", "Ten ", "Eleven ", "Twelve ", "Thirteen ", "Fourteen ", "Fifteen ", "Sixteen ", "Seventeen ", "Eighteen ", "Nineteen ")
TwoD = Array("", "Ten ", "Twenty ", "Thirty ", "Forty ", "Fifty ", "Sixty ", "Seventy ", "Eighty ", "Ninety ")
mDec = InStr(1, mInput, ".", 1)
If mDec = 0 Then mAmount = mInput
If mDec <> 0 Then mDecWhat = Right(mInput, Len(mInput) - mDec): mAmount = mInput: mInput = Mid(mInput, 1, mDec - 1)
If Len(mInput) > 12 Then Exit Function
If Len(mInput) <= 3 Then mNumberOfDigits = Array(mInput, "", "", "") If Len(mInput) >= 4 And Len(mInput) <= 6 Then mNumberOfDigits = Array(Mid(mInput, 1, Len(mInput) - 3), Right(mInput, 3), "", "") If Len(mInput) >= 7 And Len(mInput) <= 9 Then mNumberOfDigits = Array(Mid(mInput, 1, Len(mInput) - 6), Mid(mInput, Len(mInput) - 5, 3), Right(mInput, 3), "") If Len(mInput) >= 10 And Len(mInput) <= 12 Then mNumberOfDigits = Array(Mid(mInput, 1, Len(mInput) - 9), Mid(mInput, Len(mInput) - 8, 3), Mid(mInput, Len(mInput) - 5, 3), Right(mInput, 3)) If Len(mInput) <= 3 Then mNumberOfDigits = Array(mInput, "", "", "") If Len(mInput) >= 4 And Len(mInput) <= 5 Then mNumberOfDigits = Array(Mid(mInput, 1, Len(mInput) - 3), Right(mInput, 3), "", "") If Len(mInput) >= 6 And Len(mInput) <= 7 Then mNumberOfDigits = Array(Mid(mInput, 1, Len(mInput) - 5), Mid(mInput, Len(mInput) - 4, 2), Right(mInput, 3), "") If Len(mInput) >= 8 And Len(mInput) <= 9 Then mNumberOfDigits = Array(Mid(mInput, 1, Len(mInput) - 7), Mid(mInput, Len(mInput) - 6, 2), Mid(mInput, Len(mInput) - 4, 2), Right(mInput, 3)) For mCntr = 0 To IIf(Len(mInput) <= 3, 0, IIf(Len(mInput) >= 4 And Len(mInput) <= 5, 1, IIf(Len(mInput) >= 6 And Len(mInput) <= 7, 2, IIf(Len(mInput) >= 8 And Len(mInput) <= 9, 3, 0)))) If Len(mNumberOfDigits(mCntr)) = 3 Then Word = Word & OneD(Val(Left(mNumberOfDigits(mCntr), 1))) & IIf(Left(mNumberOfDigits(mCntr), 1) <> "0", "Hundred", "")
If Mid(mNumberOfDigits(mCntr), 2, 2) <= 19 Then Word = Word & " " & OneD(Val(Mid(mNumberOfDigits(mCntr), 2))) Else If Mid(mNumberOfDigits(mCntr), 2, 1) >= 1 Then Word = Word & " " & TwoD(Val(Mid(mNumberOfDigits(mCntr), 2, 1))) & IIf(Right(mNumberOfDigits(mCntr), 1) >= 1, OneD(Right(mNumberOfDigits(mCntr), 1)), "")
ElseIf Len(mNumberOfDigits(mCntr)) = 2 Then
If Val(mNumberOfDigits(mCntr)) <= 19 Then Word = Word & " " & OneD(Val(mNumberOfDigits(mCntr))) Else If Val(mNumberOfDigits(mCntr)) >= 2 Then Word = Word & " " & TwoD(Val(Left(mNumberOfDigits(mCntr), 1))) & IIf(Right(mNumberOfDigits(mCntr), 1) >= 1, OneD(Val(Right(mNumberOfDigits(mCntr), 1))), "")
ElseIf Len(mNumberOfDigits(mCntr)) = 1 Then
Word = Word & " " & OneD(Val(mNumberOfDigits(mCntr)))
End If
If Len(mInput) >= 4 And Len(mInput) <= 5 Then Word = Word & IIf(mCntr = 0 And mNumberOfDigits(0) > 0, "Thousand", "")
If Len(mInput) >= 6 And Len(mInput) <= 7 Then Word = Word & IIf(mCntr = 0 And mNumberOfDigits(0) > 0, "Lakh", IIf(mCntr = 1 And mNumberOfDigits(1) > 0, "Thousand ", ""))
If Len(mInput) >= 8 And Len(mInput) <= 9 Then Word = Word & IIf(mCntr = 0 And mNumberOfDigits(0) > 0, "Crore", IIf(mCntr = 1 And mNumberOfDigits(1) > 0, "Lakh", IIf(mCntr = 2 And mNumberOfDigits(2) > 0, "Thousands ", "")))
Next
If Val(mAmount) > 0 Then Word = Word
If mDec <> 0 Then
If Val(mDecWhat) >= 1 And Val(mDecWhat) <= 19 Then Word = Word & " and " & OneD(Val(mDecWhat)) & " Paise" ElseIf Val(mDecWhat) >= 2 Then
Word = Word & " and " & TwoD(Val(Left(mDecWhat, 1))) & IIf(Right(mDecWhat, 1) >= 1, " " & OneD(Val(Right(mDecWhat, 1))) & " Paise", " Paise")
End If
End If
Convert = LTrim(Word): Word = ""
End Function

I am sharing this number to word conversion using indian rupee currency for free all i ask is to leave your comments here :)