Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131

    converting number into words

    Hi, I'm from nepal. I got code for converting number into words.


    Code:
    Function ConvertCurrencyToEnglish(ByVal MyNumber)On Error GoTo ConvertCurrencyToEnglish_Err
    
    
    Dim Temp
             Dim Rupees, Paisas
             Dim DecimalPlace, Count
    
    
             ReDim Place(9) As String
             Place(2) = " Thousand "
             Place(3) = " Million "
             Place(4) = " Billion "
             Place(5) = " Trillion "
    
    
             ' Convert MyNumber to a string, trimming extra spaces.
             MyNumber = Trim(Str(MyNumber))
    
    
             ' Find decimal place.
             DecimalPlace = InStr(MyNumber, ".")
    
    
             ' If we find decimal place...
             If DecimalPlace > 0 Then
                ' Convert Paisas
                Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
                Paisas = ConvertTens(Temp)
    
    
                ' Strip off Paisas from remainder to convert.
                MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
             End If
    
    
             Count = 1
             Do While MyNumber <> ""
                ' Convert last 3 digits of MyNumber to English Rupees.
                Temp = ConvertHundreds(Right(MyNumber, 3))
                If Temp <> "" Then Rupees = Temp & Place(Count) & Rupees
                If Len(MyNumber) > 3 Then
                   ' Remove last 3 converted digits from MyNumber.
                   MyNumber = Left(MyNumber, Len(MyNumber) - 3)
                Else
                   MyNumber = ""
                End If
                Count = Count + 1
             Loop
    
    
             ' Clean up Rupees.
             Select Case Rupees
                Case ""
                   Rupees = "No Rupees"
                Case "One"
                   Rupees = "One Rupee"
                Case Else
                   Rupees = Rupees & " Rupees"
             End Select
    
    
             ' Clean up Paisas.
             Select Case Paisas
                Case ""
                   Paisas = " And No Paisas"
                Case "One"
                   Paisas = " And One Paisa"
                Case Else
                   Paisas = " And " & Paisas & " Paisas"
             End Select
    
    
             ConvertCurrencyToEnglish = Rupees & Paisas
    
    
    
    
    ConvertCurrencyToEnglish_Exit:
        Exit Function
    
    
    ConvertCurrencyToEnglish_Err:
        Select Case MsgBox(Error$, , "LoanAPP")
        End Select
        Resume ConvertCurrencyToEnglish_Exit
                   End Function
    
    
          Private Function ConvertHundreds(ByVal MyNumber)
          On Error GoTo ConvertHundreds_Err
    
    
    Dim Result As String
    
    
             ' Exit if there is nothing to convert.
             If Val(MyNumber) = 0 Then Exit Function
    
    
             ' Append leading zeros to number.
             MyNumber = Right("000" & MyNumber, 3)
    
    
             ' Do we have a hundreds place digit to convert?
             If Left(MyNumber, 1) <> "0" Then
                Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "
             End If
    
    
             ' Do we have a tens place digit to convert?
             If Mid(MyNumber, 2, 1) <> "0" Then
                Result = Result & ConvertTens(Mid(MyNumber, 2))
             Else
                ' If not, then convert the ones place digit.
                Result = Result & ConvertDigit(Mid(MyNumber, 3))
             End If
    
    
             ConvertHundreds = Trim(Result)
    
    
    ConvertHundreds_Exit:
        Exit Function
    
    
    ConvertHundreds_Err:
       Select Case MsgBox(Error$, , "LoanAPP")
        End Select
        Resume ConvertHundreds_Exit
             
          End Function
    
    
          Private Function ConvertTens(ByVal MyTens)
             On Error GoTo ConvertTens_Err
    
    
    Dim Result As String
    
    
             ' Is value between 10 and 19?
             If Val(Left(MyTens, 1)) = 1 Then
                Select Case Val(MyTens)
                   Case 10: Result = "Ten"
                   Case 11: Result = "Eleven"
                   Case 12: Result = "Twelve"
                   Case 13: Result = "Thirteen"
                   Case 14: Result = "Fourteen"
                   Case 15: Result = "Fifteen"
                   Case 16: Result = "Sixteen"
                   Case 17: Result = "Seventeen"
                   Case 18: Result = "Eighteen"
                   Case 19: Result = "Nineteen"
                   Case Else
                End Select
             Else
                ' .. otherwise it's between 20 and 99.
                Select Case Val(Left(MyTens, 1))
                   Case 2: Result = "Twenty "
                   Case 3: Result = "Thirty "
                   Case 4: Result = "Forty "
                   Case 5: Result = "Fifty "
                   Case 6: Result = "Sixty "
                   Case 7: Result = "Seventy "
                   Case 8: Result = "Eighty "
                   Case 9: Result = "Ninety "
                   Case Else
                End Select
    
    
                ' Convert ones place digit.
                Result = Result & ConvertDigit(Right(MyTens, 1))
             End If
    
    
             ConvertTens = Result
    
    
    ConvertTens_Exit:
        Exit Function
    
    
    ConvertTens_Err:
        Select Case MsgBox(Error$, , "LoanAPP")
        End Select
        Resume ConvertTens_Exit
        
          End Function
    
    
          Private Function ConvertDigit(ByVal MyDigit)
           On Error GoTo ConvertDigit_Err
    
    
    Select Case Val(MyDigit)
                Case 1: ConvertDigit = "One"
                Case 2: ConvertDigit = "Two"
                Case 3: ConvertDigit = "Three"
                Case 4: ConvertDigit = "Four"
                Case 5: ConvertDigit = "Five"
                Case 6: ConvertDigit = "Six"
                Case 7: ConvertDigit = "Seven"
                Case 8: ConvertDigit = "Eight"
                Case 9: ConvertDigit = "Nine"
                Case Else: ConvertDigit = ""
             End Select
    
    
    
    
    ConvertDigit_Exit:
        Exit Function
    
    
    ConvertDigit_Err:
        Select Case MsgBox(Error$, , "LoanAPP")
        End Select
        Resume ConvertDigit_Exit
                   End Function
    This code converts 999,999,999,999
    as "Nine Hundred Ninety Nine Billion Nine Hundred Ninety Nine Million Nine Hundred Ninety Nine Thousand Nine Hundred and Ninety Nine"
    but I Needed as " Nine Kharab Ninety Nine Arab Ninety Nine Karod Ninety Nine Lakh Ninety Nine Thousand Nine Hundred and Ninety Nine"
    and separated as "9,99,99,99,99,999"

    Thanks in Advance

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Interesting problem

    Try this:
    Code:
    Option Compare Database  '<<= should be at the top of EVERY module
    Option Explicit          '<<= should be at the top of EVERY module
    
    Function ConvertCurrencyToEnglish(ByVal MyNumber)
       On Error GoTo ConvertCurrencyToEnglish_Err
    
       Dim Temp As String
       Dim Rupees, Paisas
       Dim DecimalPlace, Kounter As Integer
    
    
       ReDim Place(9) As String
       Place(2) = " Thousand "
       Place(3) = " Lakh "
       Place(4) = " Karod "
       Place(5) = " Arab "
       Place(6) = " Kharab "
    
       ' Convert MyNumber to a string, trimming extra spaces.
       MyNumber = Trim(Str(MyNumber))
    
       ' Find decimal place.
       DecimalPlace = InStr(MyNumber, ".")
    
       ' If we find decimal place...
       If DecimalPlace > 0 Then
          ' Convert Paisas
          Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
          Paisas = ConvertTens(Temp)
    
          ' Strip off Paisas from remainder to convert.
          MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
       End If
    
       Kounter = 1
       Do While MyNumber <> ""
          Select Case Kounter
             Case 1  'Convert last 3 digits of MyNumber to words.
                Temp = ConvertHundreds(Right(MyNumber, 3), 3)
                If Temp <> "" Then Rupees = Temp & Place(Kounter) & Rupees
                If Len(MyNumber) > 3 Then
                   ' Remove last 3 converted digits from MyNumber.
                   MyNumber = Left(MyNumber, Len(MyNumber) - 3)
                Else
                   MyNumber = ""
                End If
    
             Case Is > 1
                ' Convert remaining digits of MyNumber to words.
                Temp = ConvertHundreds(Right(MyNumber, 2), 2)
                If Temp <> "" Then Rupees = Temp & Place(Kounter) & Rupees
                If Len(MyNumber) > 2 Then
                   ' Remove last 3 converted digits from MyNumber.
                   MyNumber = Left(MyNumber, Len(MyNumber) - 2)
                Else
                   MyNumber = ""
                End If
    
          End Select
          Kounter = Kounter + 1
       Loop
    
       ' Clean up Rupees.
       Select Case Rupees
          Case ""
             Rupees = "No Rupees"
          Case "One"
             Rupees = "One Rupee"
          Case Else
             Rupees = Rupees & " Rupees"
       End Select
    
       ' Clean up Paisas.
       Select Case Paisas
          Case ""
             Paisas = " And No Paisas"
          Case "One"
             Paisas = " And One Paisa"
          Case Else
             Paisas = " And " & Paisas & " Paisas"
       End Select
    
       ConvertCurrencyToEnglish = Rupees & Paisas
    
    ConvertCurrencyToEnglish_Exit:
       Exit Function
    
    ConvertCurrencyToEnglish_Err:
       Select Case MsgBox(Error$, , "LoanAPP")
       End Select
       Resume ConvertCurrencyToEnglish_Exit
    End Function
    
    Private Function ConvertHundreds(ByVal MyNumber, pPlaces As Integer)
       On Error GoTo ConvertHundreds_Err
    
       Dim Result As String
    
       ' Exit if there is nothing to convert.
       If Val(MyNumber) = 0 Then Exit Function
    
       Select Case pPlaces
          Case 2
             ' Append leading zeros to number.
             MyNumber = Right("00" & MyNumber, 2)
    
             ' Do we have a tens place digit to convert?
             If Mid(MyNumber, 2, 1) <> "0" Then
                Result = Result & ConvertTens(Mid(MyNumber, 1))
             Else
                ' If not, then convert the ones place digit.
                Result = Result & ConvertDigit(Mid(MyNumber, 2))
             End If
    
          Case 3
             ' Append leading zeros to number.
             MyNumber = Right("000" & MyNumber, 3)
    
             ' Do we have a hundreds place digit to convert?
             If Left(MyNumber, 1) <> "0" Then
                Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "
             End If
    
             ' Do we have a tens place digit to convert?
             If Mid(MyNumber, 2, 1) <> "0" Then
                Result = Result & ConvertTens(Mid(MyNumber, 2))
             Else
                ' If not, then convert the ones place digit.
                Result = Result & ConvertDigit(Mid(MyNumber, 3))
             End If
       End Select
    
       ConvertHundreds = Trim(Result)
    
    ConvertHundreds_Exit:
       Exit Function
    
    
    ConvertHundreds_Err:
       Select Case MsgBox(Error$, , "LoanAPP")
       End Select
       Resume ConvertHundreds_Exit
    
    End Function
    
    Private Function ConvertTens(ByVal MyTens)
       On Error GoTo ConvertTens_Err
    
       Dim Result As String
    
       ' Is value between 10 and 19?
       If Val(Left(MyTens, 1)) = 1 Then
          Select Case Val(MyTens)
             Case 10: Result = "Ten"
             Case 11: Result = "Eleven"
             Case 12: Result = "Twelve"
             Case 13: Result = "Thirteen"
             Case 14: Result = "Fourteen"
             Case 15: Result = "Fifteen"
             Case 16: Result = "Sixteen"
             Case 17: Result = "Seventeen"
             Case 18: Result = "Eighteen"
             Case 19: Result = "Nineteen"
             Case Else
          End Select
       Else
          ' .. otherwise it's between 20 and 99.
          Select Case Val(Left(MyTens, 1))
             Case 2: Result = "Twenty "
             Case 3: Result = "Thirty "
             Case 4: Result = "Forty "
             Case 5: Result = "Fifty "
             Case 6: Result = "Sixty "
             Case 7: Result = "Seventy "
             Case 8: Result = "Eighty "
             Case 9: Result = "Ninety "
             Case Else
          End Select
    
          ' Convert ones place digit.
          Result = Result & ConvertDigit(Right(MyTens, 1))
       End If
    
       ConvertTens = Result
    
    ConvertTens_Exit:
       Exit Function
    
    ConvertTens_Err:
       Select Case MsgBox(Error$, , "LoanAPP")
       End Select
       Resume ConvertTens_Exit
    
    End Function
    
    
    Private Function ConvertDigit(ByVal MyDigit)
       On Error GoTo ConvertDigit_Err
    
       Select Case Val(MyDigit)
          Case 1: ConvertDigit = "One"
          Case 2: ConvertDigit = "Two"
          Case 3: ConvertDigit = "Three"
          Case 4: ConvertDigit = "Four"
          Case 5: ConvertDigit = "Five"
          Case 6: ConvertDigit = "Six"
          Case 7: ConvertDigit = "Seven"
          Case 8: ConvertDigit = "Eight"
          Case 9: ConvertDigit = "Nine"
          Case Else: ConvertDigit = ""
       End Select
    
    ConvertDigit_Exit:
       Exit Function
    
    ConvertDigit_Err:
       Select Case MsgBox(Error$, , "LoanAPP")
       End Select
       Resume ConvertDigit_Exit
    End Function

  3. #3
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131
    Thank You from my core part of my heart.

    I want to add more count.

    Place(2) = " Thousand "
    Place(3) = " Lakh "
    Place(4) = " Karod "
    Place(5) = " Arab "
    Place(6) = " Kharab "
    Place(7) = "Nill"
    Place(8) = "Padam"
    Place(9) = "Sankh"
    Place(10) = "Mahasankh"
    where i have change?

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    All of these units
    Place(3) = " Lakh "
    Place(4) = " Karod "
    Place(5) = " Arab "
    Place(6) = " Kharab "
    Place(7) = "Nill"
    Place(8) = "Padam"
    Place(9) = "Sankh"
    Place(10) = "Mahasankh"
    are 2 places? (99,99,99,99,99,99,99,99,99,xxx)

    I finally got the code to work (I think) with the number out to Mahasankh place, but that number is too large for any number type in Access, so it has to be a text field.

    Try this:
    Code:
    Function ConvertCurrencyToEnglish(ByVal pMyNumber As String)
       On Error GoTo ConvertCurrencyToEnglish_Err
    
       Dim Temp As String
       Dim Rupees, Paisas
       Dim DecimalPlace, Kounter As Integer
       Dim MyNumber As String
    
       ReDim Place(15) As String
       Place(2) = " Thousand "
       Place(3) = " Lakh "
       Place(4) = " Karod "
       Place(5) = " Arab "
       Place(6) = " Kharab "
       Place(7) = " Nill "
       Place(8) = " Padam "
       Place(9) = " Sankh "
       Place(10) = " Mahasankh "
    
       ' Trim beginning and ending spaces from MyNumber
       MyNumber = Trim(pMyNumber)
       
       '   remove the commas
       MyNumber = Replace(MyNumber, ",", "")
    
       ' Find decimal place.
       DecimalPlace = InStr(MyNumber, ".")
    
       ' If we find decimal place...
       If DecimalPlace > 0 Then
          ' Convert Paisas
          Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
          Paisas = ConvertTens(Temp)
    
          ' Strip off Paisas from remainder to convert.
          MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
       End If
    
       Kounter = 1
       Do While MyNumber <> ""
          Select Case Kounter
             Case 1  'Convert last 3 digits of MyNumber to words.
                Temp = ConvertHundreds(Right(MyNumber, 3), 3)
                If Temp <> "" Then Rupees = Temp & Place(Kounter) & Rupees
                If Len(MyNumber) > 3 Then
                   ' Remove last 3 converted digits from MyNumber.
                   MyNumber = Left(MyNumber, Len(MyNumber) - 3)
                Else
                   MyNumber = ""
                End If
    
             Case Is > 1
                ' Convert remaining digits of MyNumber to words.
                Temp = ConvertHundreds(Right(MyNumber, 2), 2)
                If Temp <> "" Then Rupees = Temp & Place(Kounter) & Rupees
                If Len(MyNumber) > 2 Then
                   ' Remove last 3 converted digits from MyNumber.
                   MyNumber = Left(MyNumber, Len(MyNumber) - 2)
                Else
                   MyNumber = ""
                End If
    
          End Select
          Kounter = Kounter + 1
         '     Forms!form1.Text3 = Rupees   '<<<---- I should have deleted this line :(
       Loop
    
       ' Clean up Rupees.
       Select Case Rupees
          Case ""
             Rupees = "No Rupees"
          Case "One"
             Rupees = "One Rupee"
          Case Else
             Rupees = Rupees & " Rupees"
       End Select
    
       ' Clean up Paisas.
       Select Case Paisas
          Case ""
             Paisas = " And No Paisas"
          Case "One"
             Paisas = " And One Paisa"
          Case Else
             Paisas = " And " & Trim(Paisas) & " Paisas"
       End Select
    
       ConvertCurrencyToEnglish = Rupees & Paisas
    
    ConvertCurrencyToEnglish_Exit:
       Exit Function
    
    ConvertCurrencyToEnglish_Err:
       Select Case MsgBox(Error$, , "LoanAPP")
       End Select
       Resume ConvertCurrencyToEnglish_Exit
       
    End Function
    You only have to replace this one function.
    Last edited by ssanfu; 02-05-2014 at 11:30 PM. Reason: left in a debugging line - See the code

  5. #5
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131
    how many digits supports in number field in access?

    Thank You.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I can enter 9,999,999,999,999.99 (that is 13 nines plus two decimals.)
    then the number is converted to scientific format which is passed to the function. Since the number passed to the function is 1E+15, the function throws an error.

    You would have to experiment using your localized settings to see what the number limits are.




    Also note: I left in a debugging line in the code (see post #4). I highlighted the offending line which should be removed. If the line left in, it will cause an error or the function will not execute.

  7. #7
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131
    Thank You.

  8. #8
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131
    Hello buddy!

    I'am using your post #4 code but there is probem on 20 to 90 conversion.

    Thank You

  9. #9
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    So what is the problem? Need a little more information....
    Error messages? What is happening or what is not happening?

    Post the code you are using...

  10. #10
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131
    Option Compare Database '<<= should be at the top of EVERY moduleOption Explicit '<<= should be at the top of EVERY module

    Function ConvertCurrencyToEnglish(ByVal MyNumber)
    On Error GoTo ConvertCurrencyToEnglish_Err

    Dim Temp As String
    Dim Rupees, Paisas
    Dim DecimalPlace, Kounter As Integer


    ReDim Place(9) As String
    Place(2) = " Thousand "
    Place(3) = " Lakh "
    Place(4) = " Karod "
    Place(5) = " Arab "
    Place(6) = " Kharab "

    ' Convert MyNumber to a string, trimming extra spaces.
    MyNumber = Trim(Str(MyNumber))

    ' Find decimal place.
    DecimalPlace = InStr(MyNumber, ".")

    ' If we find decimal place...
    If DecimalPlace > 0 Then
    ' Convert Paisas
    Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
    Paisas = ConvertTens(Temp)

    ' Strip off Paisas from remainder to convert.
    MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If

    Kounter = 1
    Do While MyNumber <> ""
    Select Case Kounter
    Case 1 'Convert last 3 digits of MyNumber to words.
    Temp = ConvertHundreds(Right(MyNumber, 3), 3)
    If Temp <> "" Then Rupees = Temp & Place(Kounter) & Rupees
    If Len(MyNumber) > 3 Then
    ' Remove last 3 converted digits from MyNumber.
    MyNumber = Left(MyNumber, Len(MyNumber) - 3)
    Else
    MyNumber = ""
    End If

    Case Is > 1
    ' Convert remaining digits of MyNumber to words.
    Temp = ConvertHundreds(Right(MyNumber, 2), 2)
    If Temp <> "" Then Rupees = Temp & Place(Kounter) & Rupees
    If Len(MyNumber) > 2 Then
    ' Remove last 3 converted digits from MyNumber.
    MyNumber = Left(MyNumber, Len(MyNumber) - 2)
    Else
    MyNumber = ""
    End If

    End Select
    Kounter = Kounter + 1
    Loop

    ' Clean up Rupees.
    Select Case Rupees
    Case ""
    Rupees = "No Rupees"
    Case "One"
    Rupees = "One Rupee"
    Case Else
    Rupees = Rupees & " Rupees"
    End Select

    ' Clean up Paisas.
    Select Case Paisas
    Case ""
    Paisas = " And No Paisas"
    Case "One"
    Paisas = " And One Paisa"
    Case Else
    Paisas = " And " & Paisas & " Paisas"
    End Select

    ConvertCurrencyToEnglish = Rupees & Paisas

    ConvertCurrencyToEnglish_Exit:
    Exit Function

    ConvertCurrencyToEnglish_Err:
    Select Case MsgBox(Error$, , "LoanAPP")
    End Select
    Resume ConvertCurrencyToEnglish_Exit
    End Function

    Private Function ConvertHundreds(ByVal MyNumber, pPlaces As Integer)
    On Error GoTo ConvertHundreds_Err

    Dim Result As String

    ' Exit if there is nothing to convert.
    If Val(MyNumber) = 0 Then Exit Function

    Select Case pPlaces
    Case 2
    ' Append leading zeros to number.
    MyNumber = Right("00" & MyNumber, 2)

    ' Do we have a tens place digit to convert?
    If Mid(MyNumber, 2, 1) <> "0" Then
    Result = Result & ConvertTens(Mid(MyNumber, 1))
    Else
    ' If not, then convert the ones place digit.
    Result = Result & ConvertDigit(Mid(MyNumber, 2))
    End If

    Case 3
    ' Append leading zeros to number.
    MyNumber = Right("000" & MyNumber, 3)

    ' Do we have a hundreds place digit to convert?
    If Left(MyNumber, 1) <> "0" Then
    Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "
    End If

    ' Do we have a tens place digit to convert?
    If Mid(MyNumber, 2, 1) <> "0" Then
    Result = Result & ConvertTens(Mid(MyNumber, 2))
    Else
    ' If not, then convert the ones place digit.
    Result = Result & ConvertDigit(Mid(MyNumber, 3))
    End If
    End Select

    ConvertHundreds = Trim(Result)

    ConvertHundreds_Exit:
    Exit Function


    ConvertHundreds_Err:
    Select Case MsgBox(Error$, , "LoanAPP")
    End Select
    Resume ConvertHundreds_Exit

    End Function

    Private Function ConvertTens(ByVal MyTens)
    On Error GoTo ConvertTens_Err

    Dim Result As String

    ' Is value between 10 and 19?
    If Val(Left(MyTens, 1)) = 1 Then
    Select Case Val(MyTens)
    Case 10: Result = "Ten"
    Case 11: Result = "Eleven"
    Case 12: Result = "Twelve"
    Case 13: Result = "Thirteen"
    Case 14: Result = "Fourteen"
    Case 15: Result = "Fifteen"
    Case 16: Result = "Sixteen"
    Case 17: Result = "Seventeen"
    Case 18: Result = "Eighteen"
    Case 19: Result = "Nineteen"
    Case Else
    End Select
    Else
    ' .. otherwise it's between 20 and 99.
    Select Case Val(Left(MyTens, 1))
    Case 2: Result = "Twenty "
    Case 3: Result = "Thirty "
    Case 4: Result = "Forty "
    Case 5: Result = "Fifty "
    Case 6: Result = "Sixty "
    Case 7: Result = "Seventy "
    Case 8: Result = "Eighty "
    Case 9: Result = "Ninety "
    Case Else
    End Select

    ' Convert ones place digit.
    Result = Result & ConvertDigit(Right(MyTens, 1))
    End If

    ConvertTens = Result

    ConvertTens_Exit:
    Exit Function

    ConvertTens_Err:
    Select Case MsgBox(Error$, , "LoanAPP")
    End Select
    Resume ConvertTens_Exit

    End Function


    Private Function ConvertDigit(ByVal MyDigit)
    On Error GoTo ConvertDigit_Err

    Select Case Val(MyDigit)
    Case 1: ConvertDigit = "One"
    Case 2: ConvertDigit = "Two"
    Case 3: ConvertDigit = "Three"
    Case 4: ConvertDigit = "Four"
    Case 5: ConvertDigit = "Five"
    Case 6: ConvertDigit = "Six"
    Case 7: ConvertDigit = "Seven"
    Case 8: ConvertDigit = "Eight"
    Case 9: ConvertDigit = "Nine"
    Case Else: ConvertDigit = ""
    End Select

    ConvertDigit_Exit:
    Exit Function

    ConvertDigit_Err:
    Select Case MsgBox(Error$, , "LoanAPP")
    End Select
    Resume ConvertDigit_Exit End Function
    This code not converting 10 thousand, 20 thousand, 30 thousand, 40 thousand ,50 thousand, 60 thousand, 70 thousand, 80 thousand and 90 Thousand

  11. #11
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    This code is not the same as the code in Post #4.
    It looks like you are using the code from Post #2.


    Try the code in Post #4.

  12. #12
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131
    same problem exists
    with code
    Option Compare Database '<<= should be at the top of EVERY moduleOption Explicit '<<= should be at the top of EVERY module


    Function ConvertCurrencyToEnglish(ByVal pMyNumber As String)
    On Error GoTo ConvertCurrencyToEnglish_Err


    Dim Temp As String
    Dim Rupees, Paisas
    Dim DecimalPlace, Kounter As Integer
    Dim MyNumber As String


    ReDim Place(15) As String
    Place(2) = " Thousand "
    Place(3) = " Lakh "
    Place(4) = " Karod "
    Place(5) = " Arab "
    Place(6) = " Kharab "
    Place(7) = " Nill "
    Place(8) = " Padam "
    Place(9) = " Sankh "
    Place(10) = " Mahasankh "


    ' Trim beginning and ending spaces from MyNumber
    MyNumber = Trim(pMyNumber)

    ' remove the commas
    MyNumber = Replace(MyNumber, ",", "")


    ' Find decimal place.
    DecimalPlace = InStr(MyNumber, ".")


    ' If we find decimal place...
    If DecimalPlace > 0 Then
    ' Convert Paisas
    Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
    Paisas = ConvertTens(Temp)


    ' Strip off Paisas from remainder to convert.
    MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
    End If


    Kounter = 1
    Do While MyNumber <> ""
    Select Case Kounter
    Case 1 'Convert last 3 digits of MyNumber to words.
    Temp = ConvertHundreds(Right(MyNumber, 3), 3)
    If Temp <> "" Then Rupees = Temp & Place(Kounter) & Rupees
    If Len(MyNumber) > 3 Then
    ' Remove last 3 converted digits from MyNumber.
    MyNumber = Left(MyNumber, Len(MyNumber) - 3)
    Else
    MyNumber = ""
    End If


    Case Is > 1
    ' Convert remaining digits of MyNumber to words.
    Temp = ConvertHundreds(Right(MyNumber, 2), 2)
    If Temp <> "" Then Rupees = Temp & Place(Kounter) & Rupees
    If Len(MyNumber) > 2 Then
    ' Remove last 3 converted digits from MyNumber.
    MyNumber = Left(MyNumber, Len(MyNumber) - 2)
    Else
    MyNumber = ""
    End If


    End Select
    Kounter = Kounter + 1
    ' Forms!form1.Text3 = Rupees '<<<---- I should have deleted this line
    Loop


    ' Clean up Rupees.
    Select Case Rupees
    Case ""
    Rupees = "No Rupees"
    Case "One"
    Rupees = "One Rupee"
    Case Else
    Rupees = Rupees & " Rupees"
    End Select


    ' Clean up Paisas.
    Select Case Paisas
    Case ""
    Paisas = " And No Paisas"
    Case "One"
    Paisas = " And One Paisa"
    Case Else
    Paisas = " And " & Trim(Paisas) & " Paisas"
    End Select


    ConvertCurrencyToEnglish = Rupees & Paisas


    ConvertCurrencyToEnglish_Exit:
    Exit Function


    ConvertCurrencyToEnglish_Err:
    Select Case MsgBox(Error$, , "LoanAPP")
    End Select
    Resume ConvertCurrencyToEnglish_Exit

    End Function
    Private Function ConvertHundreds(ByVal MyNumber, pPlaces As Integer)
    On Error GoTo ConvertHundreds_Err


    Dim Result As String


    ' Exit if there is nothing to convert.
    If Val(MyNumber) = 0 Then Exit Function


    Select Case pPlaces
    Case 2
    ' Append leading zeros to number.
    MyNumber = Right("00" & MyNumber, 2)


    ' Do we have a tens place digit to convert?
    If Mid(MyNumber, 2, 1) <> "0" Then
    Result = Result & ConvertTens(Mid(MyNumber, 1))
    Else
    ' If not, then convert the ones place digit.
    Result = Result & ConvertDigit(Mid(MyNumber, 2))
    End If


    Case 3
    ' Append leading zeros to number.
    MyNumber = Right("000" & MyNumber, 3)


    ' Do we have a hundreds place digit to convert?
    If Left(MyNumber, 1) <> "0" Then
    Result = ConvertDigit(Left(MyNumber, 1)) & " Hundred "
    End If


    ' Do we have a tens place digit to convert?
    If Mid(MyNumber, 2, 1) <> "0" Then
    Result = Result & ConvertTens(Mid(MyNumber, 2))
    Else
    ' If not, then convert the ones place digit.
    Result = Result & ConvertDigit(Mid(MyNumber, 3))
    End If
    End Select


    ConvertHundreds = Trim(Result)


    ConvertHundreds_Exit:
    Exit Function




    ConvertHundreds_Err:
    Select Case MsgBox(Error$, , "LoanAPP")
    End Select
    Resume ConvertHundreds_Exit


    End Function


    Private Function ConvertTens(ByVal MyTens)
    On Error GoTo ConvertTens_Err


    Dim Result As String


    ' Is value between 10 and 19?
    If Val(Left(MyTens, 1)) = 1 Then
    Select Case Val(MyTens)
    Case 10: Result = "Ten"
    Case 11: Result = "Eleven"
    Case 12: Result = "Twelve"
    Case 13: Result = "Thirteen"
    Case 14: Result = "Fourteen"
    Case 15: Result = "Fifteen"
    Case 16: Result = "Sixteen"
    Case 17: Result = "Seventeen"
    Case 18: Result = "Eighteen"
    Case 19: Result = "Nineteen"
    Case Else
    End Select
    Else
    ' .. otherwise it's between 20 and 99.
    Select Case Val(Left(MyTens, 1))
    Case 2: Result = "Twenty "
    Case 3: Result = "Thirty "
    Case 4: Result = "Forty "
    Case 5: Result = "Fifty "
    Case 6: Result = "Sixty "
    Case 7: Result = "Seventy "
    Case 8: Result = "Eighty "
    Case 9: Result = "Ninety "
    Case Else
    End Select


    ' Convert ones place digit.
    Result = Result & ConvertDigit(Right(MyTens, 1))
    End If


    ConvertTens = Result


    ConvertTens_Exit:
    Exit Function


    ConvertTens_Err:
    Select Case MsgBox(Error$, , "LoanAPP")
    End Select
    Resume ConvertTens_Exit


    End Function




    Private Function ConvertDigit(ByVal MyDigit)
    On Error GoTo ConvertDigit_Err


    Select Case Val(MyDigit)
    Case 1: ConvertDigit = "One"
    Case 2: ConvertDigit = "Two"
    Case 3: ConvertDigit = "Three"
    Case 4: ConvertDigit = "Four"
    Case 5: ConvertDigit = "Five"
    Case 6: ConvertDigit = "Six"
    Case 7: ConvertDigit = "Seven"
    Case 8: ConvertDigit = "Eight"
    Case 9: ConvertDigit = "Nine"
    Case Else: ConvertDigit = ""
    End Select


    ConvertDigit_Exit:
    Exit Function


    ConvertDigit_Err:
    Select Case MsgBox(Error$, , "LoanAPP")
    End Select
    Resume ConvertDigit_Exit
    End Function


  13. #13
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131
    Should this code can be used in Query?

  14. #14
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    It could be used in a query....

    You were right.... it didn't convert all numbers correctly.

    Replace all of the code with the code in the attachment.

  15. #15
    joshynaresh is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Aug 2013
    Posts
    131
    not working this code.
    LoanAPP can't find the form 'form1' referred to in a macro expression or visual basic code
    when i used this function in my form.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Converting a Number to Decimal
    By lwilt in forum Access
    Replies: 5
    Last Post: 10-11-2013, 05:02 PM
  2. Converting lookup text field to number for primary
    By Ruegen in forum Database Design
    Replies: 4
    Last Post: 09-11-2013, 08:23 PM
  3. Converting text to number type
    By togo in forum Access
    Replies: 12
    Last Post: 09-18-2012, 12:59 PM
  4. Converting negative number to positive using QBE??
    By shabbaranks in forum Queries
    Replies: 5
    Last Post: 03-23-2012, 08:57 AM
  5. Replies: 1
    Last Post: 09-06-2011, 05:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums