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 :)

4 comments:

  1. Sir,
    Indian currency system is in the following style.
    Eg.Rs.42982782.95
    Rupees Four Crore Twenty Nine Lakh Eighty Two Thousand Seven Hundred Eighty Two and Paise Ninety
    Five Only.

    ReplyDelete
    Replies
    1. hello master, thanks for the info. i'll try to fix my code... as soon as i am done, i will published it here...
      thanks for visiting my blog.

      Delete
    2. can you send me this ms access example database
      thanks.
      my email: TARGETGROUP10@GMAIL.COM

      Delete
  2. hello i am new to VB, sir i have followed stems mentioned above, getting message altert " MS cannot find the object "Me". if 'me' is new micro or group of macro please ensure it saved properly or named properly like this. please help

    regards

    ReplyDelete