none
number to word RRS feed

  • Question

  • Hi

    There in this thread, https://social.msdn.microsoft.com/Forums/office/en-US/cccf795b-6bf0-4477-8576-3d65cfb42de9/formulla-for-number-to-word-in-hindi?forum=exceldev   , a solution for number to word is ok and working. I need same work with this string for it's same result in hindi.  I tried all but failed. String 1 as a whole should be included in code.

    Private numStr1(0 To 100) As String
    Private numStr2(0 To 9) As String
    Private numStrInit As Long
    Private Sub InitNumStr()
    numStr1(0) = ""
    numStr1(1) = "one"
    numStr1(2) = "two"
    numStr1(3) = "three"
    numStr1(4) = "four"
    numStr1(5) = "five"
    numStr1(6) = "six"
    numStr1(7) = "seven"
    numStr1(8) = "eight"
    numStr1(9) = "nine"
    numStr1(10) = "ten"
    numStr1(11) = "eleven"
    numStr1(12) = "twelve"
    numStr1(13) = "thirteen"
    numStr1(14) = "fourteen"
    numStr1(15) = "fifteen"
    numStr1(16) = "sixteen"
    numStr1(17) = "seventeen"
    numStr1(18) = "eighteen"
    numStr1(19) = "nineteen"


    numStr1(20) = "twenty"
    numStr1(21) = "twenty one"
    numStr1(22) = "twenty two"
    numStr1(23) = "twenty three"
    numStr1(24) = "twenty four"
    numStr1(25) = "twenty five"
    numStr1(26) = "twenty six"
    numStr1(27) = "twenty seven"
    numStr1(28) = "twenty eight"
    numStr1(29) = "twenty nine"


    numStr1(30) = "thirty"
    numStr1(31) = "thirty one"
    numStr1(32) = "thirty two"
    numStr1(33) = "thirty three"
    numStr1(34) = "thirty four"
    numStr1(35) = "thirty five"
    numStr1(36) = "thirty six"
    numStr1(37) = "thirty seven"
    numStr1(38) = "thirty eight"
    numStr1(39) = "thirty nine"


    numStr1(40) = "forty"
    numStr1(41) = "forty one"
    numStr1(42) = "forty two"
    numStr1(43) = "forty three"
    numStr1(44) = "forty four"
    numStr1(45) = "forty five"
    numStr1(46) = "forty six"
    numStr1(47) = "forty seven"
    numStr1(48) = "forty eight"
    numStr1(49) = "forty nine"


    numStr1(50) = "fifty"
    numStr1(51) = "fifty one"
    numStr1(52) = "fifty two"
    numStr1(53) = "fifty three"
    numStr1(54) = "fifty four"
    numStr1(55) = "fifty five"
    numStr1(56) = "fifty six"
    numStr1(57) = "fifty seven"
    numStr1(58) = "fifty eight"
    numStr1(59) = "fifty nine"


    numStr1(60) = "sixty"
    numStr1(61) = "sixty one"
    numStr1(62) = "sixty two"
    numStr1(63) = "sixty three"
    numStr1(64) = "sixty four"
    numStr1(65) = "sixty five"
    numStr1(66) = "sixty six"
    numStr1(67) = "sixty seven"
    numStr1(68) = "sixty eight"
    numStr1(69) = "sixty nine"


    numStr1(70) = "seventy"
    numStr1(71) = "seventy one"
    numStr1(72) = "seventy two"
    numStr1(73) = "seventy three"
    numStr1(74) = "seventy four"
    numStr1(75) = "seventy five"
    numStr1(76) = "seventy six"
    numStr1(77) = "seventy seven"
    numStr1(78) = "seventy eight"
    numStr1(79) = "seventy nine"


    numStr1(80) = "eighty"
    numStr1(81) = "eighty one"
    numStr1(82) = "eighty two"
    numStr1(83) = "eighty three"
    numStr1(84) = "eighty four"
    numStr1(85) = "eighty five"
    numStr1(86) = "eighty six"
    numStr1(87) = "eighty seven"
    numStr1(88) = "eighty eight"
    numStr1(89) = "eighty nine"


    numStr1(90) = "ninety"
    numStr1(91) = "ninety one"
    numStr1(92) = "ninety two"
    numStr1(93) = "ninety three"
    numStr1(94) = "ninety four"
    numStr1(95) = "ninety five"
    numStr1(96) = "ninety six"
    numStr1(97) = "ninety seven"
    numStr1(98) = "ninety eight"
    numStr1(99) = "ninety nine"
    numStr1(100) = "hundred"


    numStrInit = 1
    End Sub
    Private Function GetNumberPart(ANumber As Long, Suffix As String, Divisor As Long) As String
    Dim tempIndex As Long
    Dim tempIndex2 As Long
    tempIndex = ANumber Mod Divisor
    ANumber = ANumber \ Divisor
    If tempIndex > 0 Then
    If tempIndex > 19 Then
    tempIndex2 = tempIndex \ 10
    tempIndex = tempIndex Mod 10
    End If
    GetNumberPart = Trim(numStr2(tempIndex2) & numStr1(tempIndex)) & Suffix
    End If
    End Function

    Private Function MyConcat(String1 As String, String2 As String) As String
        If Len(String1) > 0 And Len(String2) > 0 Then
            MyConcat = String1 & " " & String2
        Else
            MyConcat = String1 & String2
        End If
    End Function

    Public Function MakeNumber(ByVal ANumber As Long) As String
        Dim resultStr As String
        
        If numStrInit = 0 Then
            ' initialize constant string arrays
            InitNumStr
        End If
        
        resultStr = "Zero"
        If ANumber > 0 Then
            resultStr = GetNumberPart(ANumber, "", 100) & "  " & "Only"
            resultStr = MyConcat(GetNumberPart(ANumber, " hundred", 10), resultStr)
            resultStr = MyConcat(GetNumberPart(ANumber, " thousand", 100), resultStr)
            resultStr = "Ruppes" & ":-  " & MyConcat(GetNumberPart(ANumber, " lac", 100), resultStr)
        End If
        
        MakeNumber = resultStr
    End Function

    One more thing, I want conversion up to ten crore.

    please help. thank you.

    dockhem

    Wednesday, October 29, 2014 12:52 PM

Answers

All replies

  • Hi Hans Vogelaar,

    Thanks for reply,

    Yes, these all works fine. That in above mentioned thread also work fine. I want it to work in hindi. There is language problem, e.g. In english we have sixty ( "saath" in hindi ), five( "panch" in hindi ) when added sixty five ( not "saath panch" in hindi but "painsth" ) not similar condition in hindi. This difference runs up to hundred. So I need above string 1 should be used as it is in code so that I can use it in hindi.

    This one without change,

    numStr1(1) = "one"
    numStr1(2) = "two"
    numStr1(3) = "three"
    numStr1(4) = "four"
    numStr1(5) = "five"
    numStr1(6) = "six"
    numStr1(7) = "seven"
    numStr1(8) = "eight"
    numStr1(9) = "nine"
    numStr1(10) = "ten"
    numStr1(11) = "eleven"
    numStr1(12) = "twelve"
    numStr1(13) = "thirteen"
    numStr1(14) = "fourteen"
    numStr1(15) = "fifteen"
    numStr1(16) = "sixteen"
    numStr1(17) = "seventeen"
    numStr1(18) = "eighteen"
    numStr1(19) = "nineteen"


    numStr1(20) = "twenty"
    numStr1(21) = "twenty one"
    numStr1(22) = "twenty two"
    numStr1(23) = "twenty three"
    numStr1(24) = "twenty four"
    numStr1(25) = "twenty five"
    numStr1(26) = "twenty six"
    numStr1(27) = "twenty seven"
    numStr1(28) = "twenty eight"
    numStr1(29) = "twenty nine"


    numStr1(30) = "thirty"
    numStr1(31) = "thirty one"
    numStr1(32) = "thirty two"
    numStr1(33) = "thirty three"
    numStr1(34) = "thirty four"
    numStr1(35) = "thirty five"
    numStr1(36) = "thirty six"
    numStr1(37) = "thirty seven"
    numStr1(38) = "thirty eight"
    numStr1(39) = "thirty nine"


    numStr1(40) = "forty"
    numStr1(41) = "forty one"
    numStr1(42) = "forty two"
    numStr1(43) = "forty three"
    numStr1(44) = "forty four"
    numStr1(45) = "forty five"
    numStr1(46) = "forty six"
    numStr1(47) = "forty seven"
    numStr1(48) = "forty eight"
    numStr1(49) = "forty nine"


    numStr1(50) = "fifty"
    numStr1(51) = "fifty one"
    numStr1(52) = "fifty two"
    numStr1(53) = "fifty three"
    numStr1(54) = "fifty four"
    numStr1(55) = "fifty five"
    numStr1(56) = "fifty six"
    numStr1(57) = "fifty seven"
    numStr1(58) = "fifty eight"
    numStr1(59) = "fifty nine"


    numStr1(60) = "sixty"
    numStr1(61) = "sixty one"
    numStr1(62) = "sixty two"
    numStr1(63) = "sixty three"
    numStr1(64) = "sixty four"
    numStr1(65) = "sixty five"
    numStr1(66) = "sixty six"
    numStr1(67) = "sixty seven"
    numStr1(68) = "sixty eight"
    numStr1(69) = "sixty nine"


    numStr1(70) = "seventy"
    numStr1(71) = "seventy one"
    numStr1(72) = "seventy two"
    numStr1(73) = "seventy three"
    numStr1(74) = "seventy four"
    numStr1(75) = "seventy five"
    numStr1(76) = "seventy six"
    numStr1(77) = "seventy seven"
    numStr1(78) = "seventy eight"
    numStr1(79) = "seventy nine"


    numStr1(80) = "eighty"
    numStr1(81) = "eighty one"
    numStr1(82) = "eighty two"
    numStr1(83) = "eighty three"
    numStr1(84) = "eighty four"
    numStr1(85) = "eighty five"
    numStr1(86) = "eighty six"
    numStr1(87) = "eighty seven"
    numStr1(88) = "eighty eight"
    numStr1(89) = "eighty nine"


    numStr1(90) = "ninety"
    numStr1(91) = "ninety one"
    numStr1(92) = "ninety two"
    numStr1(93) = "ninety three"
    numStr1(94) = "ninety four"
    numStr1(95) = "ninety five"
    numStr1(96) = "ninety six"
    numStr1(97) = "ninety seven"
    numStr1(98) = "ninety eight"
    numStr1(99) = "ninety nine"
    numStr1(100) = "hundred"

    regards

    dockhem


    • Edited by dockhem2 Wednesday, October 29, 2014 11:24 PM
    Wednesday, October 29, 2014 11:22 PM
  • That in above mentioned thread also work fine. I want it to work in hindi. There is language problem, e.g. In english we have sixty ( "saath" in hindi ), five( "panch" in hindi ) when added sixty five ( not "saath panch" in hindi but "painsth" ) not similar condition in hindi. This difference runs up to hundred.

    The code you have works only for English, it is not possible to "translate" just the words to a different language.

    Each language has different expressions and rules how number words are assembled. Means you need a different code for each language.

    Andreas.

    Thursday, October 30, 2014 8:11 AM
  • Hi Andreas Killer,

    Thank you for your reply.

    I understand what you said. Please customise code using this whole string (1-100 as above). I will set it for hindi. Please do it.

    regards

    dockhem

    Thursday, October 30, 2014 9:45 AM
  • See if the workbook at https://www.dropbox.com/s/461qz6ly79klgzt/NumberToTextIndian.xlsm?dl=0 does what you want.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Proposed as answer by danishani Friday, October 31, 2014 10:15 PM
    • Marked as answer by dockhem2 Monday, November 3, 2014 3:54 PM
    Thursday, October 30, 2014 4:23 PM
  • Hi Regards, Hans Vogelaar,

    Thank you for your kind reply.

    Exactly what, I wanted. Now I will do next steps. You are extra ordinary indeed.

    regards,

    dockhem

    Friday, October 31, 2014 7:52 AM
  • Hi Andreas Killer,

    Thank you for reply,

    I need these to work, How ? I do not know because they are sln files.

    please help,

    dockhem


    • Edited by dockhem2 Saturday, November 1, 2014 4:04 AM
    Friday, October 31, 2014 7:55 AM