Convert numbers to string in text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • siyoyok007
    New Member
    • Feb 2007
    • 18

    #1

    Convert numbers to string in text box

    Hello,
    Does any one here know how to convert numbers to string? example, i input 551 in the text box and the out put will display five hundred fifty one.
    Help me...
  • vijaydiwakar
    Contributor
    • Feb 2007
    • 579

    #2
    Originally posted by siyoyok007
    Hello,
    Does any one here know how to convert numbers to string? example, i input 551 in the text box and the out put will display five hundred fifty one.
    Help me...
    DEar I've the code for this but for that u've to wait for some time .........
    I'll defenatly give u the code
    Trust me

    Comment

    • siyoyok007
      New Member
      • Feb 2007
      • 18

      #3
      Originally posted by vijaydiwakar
      DEar I've the code for this but for that u've to wait for some time .........
      I'll defenatly give u the code
      Trust me
      really?....thnx a lot....looking forward for your reply

      Comment

      • vijaydiwakar
        Contributor
        • Feb 2007
        • 579

        #4
        Originally posted by siyoyok007
        really?....thnx a lot....looking forward for your reply
        I india its 11.18 am i'm able to give u the code at 2.00pm
        is it ok?

        Comment

        • siyoyok007
          New Member
          • Feb 2007
          • 18

          #5
          Originally posted by vijaydiwakar
          I india its 11.18 am i'm able to give u the code at 2.00pm
          is it ok?
          ooo.... thnx ...it will be ok for me ..... thnx a lot again

          Comment

          • sukeshchand
            New Member
            • Jan 2007
            • 88

            #6
            Here i am posting the code.this function is for converting Indian Rupees.
            I think it will help u
            Code:
            '   This function will work upto 99,99,99,999.99 
            
            Public Function convinRS(Number As Double) As String
                Dim tempstr As String
                Dim tempnum As Double
                Dim convstr As String
                Dim partlen As Byte
                Dim ptat As Byte
                Dim digs As Integer
                
                
                convstr = ""
                ptat = InStr(1, CStr(Number), ".")
                If ptat = 0 Then
                    tempnum = CStr(Number)
                Else
                    tempnum = Mid(CStr(Number), 1, ptat)
                End If
                tempstr = Trim(CStr(tempnum))
                
                
                While Not tempnum = 0
                    
                    partlen = Len(tempstr)
                    Select Case partlen
                    Case Is >= 8
                        digs = CInt(Mid(tempstr, 1, partlen - 7))
                        convstr = diginwrd(digs)
                        If digs > 1 Then
                            convstr = convstr & "Crores "
                        Else
                            convstr = convstr & "Crore "
                        End If
                        tempstr = Right(tempstr, 7)
                    Case Is >= 6 And partlen < 8
                        digs = CInt(Mid(tempstr, 1, partlen - 5))
                        convstr = convstr & diginwrd(digs)
                        If digs > 1 Then
                            convstr = convstr & "Lakhs "
                        Else
                            convstr = convstr & "Lakh "
                        End If
                        tempstr = Right(tempstr, 5)
                        
                    Case Is < 6 And partlen >= 4
                        digs = CInt(Mid(tempstr, 1, partlen - 3))
                        convstr = convstr + diginwrd(digs)
                        convstr = convstr & "Thousand "
                        tempstr = Right(tempstr, 3)
                    Case Is <= 3
                        digs = CInt(tempstr)
                        convstr = convstr + diginwrd(digs)
                        tempstr = "0"
                    End Select
                    tempnum = CLng(tempstr)
                
                    'MsgBox tempnum & convstr
                Wend
                If ptat = 0 Then
                    tempnum = 0
                Else
                    tempnum = Val(Right(CStr(Number), Len(CStr(Number)) - ptat + 1)) * 100
                End If
            '    MsgBox convstr & tempnum
                convstr = "Rupees " & convstr
                If Not tempnum = 0 Then
                    convinRS = convstr & "And " & diginwrd(tempnum) & "Paise Only"
                Else
                    convinRS = convstr & "Only"
                End If
            End Function
            
            Public Function diginwrd(ByVal digsnum As Integer) As String
                Select Case digsnum
                Case 1
                    diginwrd = "One "
                Case 2
                    diginwrd = "Two "
                Case 3
                    diginwrd = "Three "
                Case 4
                    diginwrd = "Four "
                Case 5
                    diginwrd = "Five "
                Case 6
                    diginwrd = "Six "
                Case 7
                    diginwrd = "Seven "
                Case 8
                    diginwrd = "Eight "
                Case 9
                    diginwrd = "Nine "
                Case 10
                    diginwrd = "Ten "
                Case 11
                    diginwrd = "Eleven "
                Case 12
                    diginwrd = "Twelve "
                Case 13
                    diginwrd = "Thirteen "
                Case 14
                    diginwrd = "Fourteen "
                Case 15
                    diginwrd = "Fifteen "
                Case 16
                    diginwrd = "Sixteen "
                Case 17
                    diginwrd = "Seventeen "
                Case 18
                    diginwrd = "Eighteen "
                Case 19
                    diginwrd = "Nineteen "
                Case Is > 19
                    Dim dig As Integer
                    Dim tdigword As String
                    Dim thdig As String
                    dig = CInt(Right(CStr(digsnum), 1))
                    
                    If digsnum >= 100 Then
                        thdig = Left(CStr(digsnum), 1)
                        dig = CInt(Right(CStr(digsnum), 2))
                    Else
                        dig = CInt(Right(CStr(digsnum), 1))
                    End If
                    Select Case digsnum
                    Case Is >= 100
                        tdigword = diginwrd(CInt(thdig)) & "Hundred "
                    Case Is >= 90 And digsnum < 100
                        tdigword = "Ninety "
                    Case Is >= 80 And digsnum < 90
                        tdigword = "Eighty "
                    Case Is >= 70 And digsnum < 80
                        tdigword = "Seventy "
                    Case Is >= 60 And digsnum < 70
                        tdigword = "Sixty "
                    Case Is >= 50 And digsnum < 60
                        tdigword = "Fifty "
                    Case Is >= 40 And digsnum < 50
                        tdigword = "Forty "
                    Case Is >= 30 And digsnum < 40
                        tdigword = "Thirty "
                    Case Is >= 20 And digsnum < 30
                        tdigword = "Twenty "
                    End Select
                    diginwrd = tdigword & diginwrd(dig)
            End Select
                    
            End Function

            Comment

            • vijaydiwakar
              Contributor
              • Feb 2007
              • 579

              #7
              Originally posted by siyoyok007
              ooo.... thnx ...it will be ok for me ..... thnx a lot again
              the code
              Code:
               
              Public Function NoToWord(Acceptno As Double) As String
                  NoToWord = ""
                  
                  Dim FormatStr As String
                  FormatStr = Format(Acceptno, "000000000.00")
              
                  If Val(mid(FormatStr, 1, 2)) <> 0 Then
                      Call Word(Val(mid(FormatStr, 1, 2)))
                      NoToWord = StrConv(NoToWord & Trim(WordStr) & " CRORE ", vbProperCase)
                  End If
                  If Val(mid(FormatStr, 3, 2)) <> 0 Then
                      Call Word(Val(mid(FormatStr, 3, 2)))
                      NoToWord = StrConv(NoToWord & Trim(WordStr) & " LAC ", vbProperCase)
                  End If
                  If Val(mid(FormatStr, 5, 2)) <> 0 Then
                      Call Word(Val(mid(FormatStr, 5, 2)))
                      NoToWord = StrConv(NoToWord & Trim(WordStr) & " THOUSAND ", vbProperCase)
                  End If
                  If Val(mid(FormatStr, 7, 1)) <> 0 Then
                      Call Word(Val(mid(FormatStr, 7, 1)))
                      NoToWord = StrConv(NoToWord & Trim(WordStr) & " HUNDRED ", vbProperCase)
                  End If
                  If Val(mid(FormatStr, 8, 2)) <> 0 Then
                      Call Word(Val(mid(FormatStr, 8, 2)))
                      NoToWord = StrConv(NoToWord & Trim(WordStr) & " ", vbProperCase)
                  End If
                  If Val(mid(FormatStr, 11, 2)) <> 0 Then
                      Call Word(Val(mid(FormatStr, 11, 2)))
                      If (NoToWord <> "") Then
                        NoToWord = StrConv("Rs. " & NoToWord & "AND " & Trim(WordStr) & " PAISE ONLY", vbProperCase)
                      Else
                        NoToWord = StrConv(NoToWord & Trim(WordStr) & " PAISE ONLY", vbProperCase)
                      End If
                  Else
                     If NoToWord <> "" Then
                        NoToWord = StrConv("Rs. " & NoToWord + " ONLY", vbProperCase)
                     Else
                        NoToWord = "(In Words )"
                     End If
                  End If
              End Function
              
              Sub Word(num As Byte)
                Dim X(9) As String
                Dim x1(9) As String
                Dim x2(9) As String
                 
                
                X(1) = "ONE ": X(2) = "TWO ": X(3) = "THREE ": X(4) = "FOUR ": X(5) = "FIVE ": X(6) = "SIX ": X(7) = "SEVEN ": X(8) = "EIGHT ": X(9) = "NINE ":
                x1(1) = "TEN ": x1(2) = "TWENTY ": x1(3) = "THIRTY ": x1(4) = "FORTY ": x1(5) = "FIFTY ": x1(6) = "SIXTY ": x1(7) = "SEVENTY ": x1(8) = "EIGHTY ": x1(9) = "NINETY ":
                x2(1) = "ELEVEN ": x2(2) = "TWELVE ": x2(3) = "THIRTEEN ": x2(4) = "FOURTEEN ": x2(5) = "FIFTEEN ": x2(6) = "SIXTEEN ": x2(7) = "SEVENTEEN ": x2(8) = "EIGHTEEN ": x2(9) = "NINETEEN ":
                
                
                If num <= 9 Then ' for 1 to 9
                 WordStr = X(num)
                End If
                If num >= 10 Then ' for 10 to 99
                   If (num Mod 10 = 0) Then ' for 10,20,30....90
                      WordStr = x1(Int(num / 10))
                  End If
                  If (Int(num / 10) = 1 And (num Mod 10 <> 0)) Then 'for 11,12,13.....19
                      WordStr = x2(num Mod 10)
                  End If
                  If (Int(num / 10) > 1 And (num Mod 10 <> 0)) Then ' for 21,22,23.....99
                      WordStr = x1(Int(num / 10)) + X(num Mod 10)
                  End If
                End If
              End Sub
              the code is not created by using vb's IDE
              so pls check for errors if any
              Rs. is Ruppes the Indian Currancy so change it accordingly
              I'll not able to answer u later b'coz i'm busy with meetting
              bye

              Comment

              • sukeshchand
                New Member
                • Jan 2007
                • 88

                #8
                The code is created by vb6 and it is working on my machine. the only change in this code is you have to declare one variable (WordStr$) because that i used in two functions. and only thing you want to change is to change the Rs& Paise to your own local currency....

                Comment

                • vijaydiwakar
                  Contributor
                  • Feb 2007
                  • 579

                  #9
                  Originally posted by sukeshchand
                  The code is created by vb6 and it is working on my machine. the only change in this code is you have to declare one variable (WordStr$) because that i used in two functions. and only thing you want to change is to change the Rs& Paise to your own local currency....
                  so do u like d function?

                  Comment

                  • siyoyok007
                    New Member
                    • Feb 2007
                    • 18

                    #10
                    thanx to those who reply. Now i can finish the part... huhu.... love u all.... really hope can help others also, but i'm still newbie wiith all this stuff......
                    anyway THANX A LOT !!!

                    Comment

                    • markmcgookin
                      Recognized Expert Contributor
                      • Dec 2006
                      • 648

                      #11
                      Originally posted by vijaydiwakar
                      the code
                      Code:
                       
                      Public Function NoToWord(Acceptno As Double) As String
                          NoToWord = ""
                          
                          Dim FormatStr As String
                          FormatStr = Format(Acceptno, "000000000.00")
                      
                          If Val(mid(FormatStr, 1, 2)) <> 0 Then
                              Call Word(Val(mid(FormatStr, 1, 2)))
                              NoToWord = StrConv(NoToWord & Trim(WordStr) & " CRORE ", vbProperCase)
                          End If
                          If Val(mid(FormatStr, 3, 2)) <> 0 Then
                              Call Word(Val(mid(FormatStr, 3, 2)))
                              NoToWord = StrConv(NoToWord & Trim(WordStr) & " LAC ", vbProperCase)
                          End If
                          If Val(mid(FormatStr, 5, 2)) <> 0 Then
                              Call Word(Val(mid(FormatStr, 5, 2)))
                              NoToWord = StrConv(NoToWord & Trim(WordStr) & " THOUSAND ", vbProperCase)
                          End If
                          If Val(mid(FormatStr, 7, 1)) <> 0 Then
                              Call Word(Val(mid(FormatStr, 7, 1)))
                              NoToWord = StrConv(NoToWord & Trim(WordStr) & " HUNDRED ", vbProperCase)
                          End If
                          If Val(mid(FormatStr, 8, 2)) <> 0 Then
                              Call Word(Val(mid(FormatStr, 8, 2)))
                              NoToWord = StrConv(NoToWord & Trim(WordStr) & " ", vbProperCase)
                          End If
                          If Val(mid(FormatStr, 11, 2)) <> 0 Then
                              Call Word(Val(mid(FormatStr, 11, 2)))
                              If (NoToWord <> "") Then
                                NoToWord = StrConv("Rs. " & NoToWord & "AND " & Trim(WordStr) & " PAISE ONLY", vbProperCase)
                              Else
                                NoToWord = StrConv(NoToWord & Trim(WordStr) & " PAISE ONLY", vbProperCase)
                              End If
                          Else
                             If NoToWord <> "" Then
                                NoToWord = StrConv("Rs. " & NoToWord + " ONLY", vbProperCase)
                             Else
                                NoToWord = "(In Words )"
                             End If
                          End If
                      End Function
                      
                      Sub Word(num As Byte)
                        Dim X(9) As String
                        Dim x1(9) As String
                        Dim x2(9) As String
                         
                        
                        X(1) = "ONE ": X(2) = "TWO ": X(3) = "THREE ": X(4) = "FOUR ": X(5) = "FIVE ": X(6) = "SIX ": X(7) = "SEVEN ": X(8) = "EIGHT ": X(9) = "NINE ":
                        x1(1) = "TEN ": x1(2) = "TWENTY ": x1(3) = "THIRTY ": x1(4) = "FORTY ": x1(5) = "FIFTY ": x1(6) = "SIXTY ": x1(7) = "SEVENTY ": x1(8) = "EIGHTY ": x1(9) = "NINETY ":
                        x2(1) = "ELEVEN ": x2(2) = "TWELVE ": x2(3) = "THIRTEEN ": x2(4) = "FOURTEEN ": x2(5) = "FIFTEEN ": x2(6) = "SIXTEEN ": x2(7) = "SEVENTEEN ": x2(8) = "EIGHTEEN ": x2(9) = "NINETEEN ":
                        
                        
                        If num <= 9 Then ' for 1 to 9
                         WordStr = X(num)
                        End If
                        If num >= 10 Then ' for 10 to 99
                           If (num Mod 10 = 0) Then ' for 10,20,30....90
                              WordStr = x1(Int(num / 10))
                          End If
                          If (Int(num / 10) = 1 And (num Mod 10 <> 0)) Then 'for 11,12,13.....19
                              WordStr = x2(num Mod 10)
                          End If
                          If (Int(num / 10) > 1 And (num Mod 10 <> 0)) Then ' for 21,22,23.....99
                              WordStr = x1(Int(num / 10)) + X(num Mod 10)
                          End If
                        End If
                      End Sub
                      the code is not created by using vb's IDE
                      so pls check for errors if any
                      Rs. is Ruppes the Indian Currancy so change it accordingly
                      I'll not able to answer u later b'coz i'm busy with meetting
                      bye
                      Kudos on a great reply. I'd have just left it saying 551 ^.^

                      Comment

                      • vijaydiwakar
                        Contributor
                        • Feb 2007
                        • 579

                        #12
                        Originally posted by markmcgookin
                        Kudos on a great reply. I'd have just left it saying 551 ^.^
                        would u pls explan 551 pls

                        Comment

                        • markmcgookin
                          Recognized Expert Contributor
                          • Dec 2006
                          • 648

                          #13
                          Originally posted by vijaydiwakar
                          would u pls explan 551 pls
                          Hehe, I would have just left the code as it was, I wouldn't have translated it into words. (This wasn't a very helpful post, just a congrats to the person who solved the problem)

                          Comment

                          • jasbirs1982
                            New Member
                            • Mar 2008
                            • 1

                            #14
                            Hi,

                            I would like to convert 211,11,21,200.0 0 into
                            Two hundred eleven crores, eleven lakhs, twenty one thousand and two hundred only.

                            please help

                            thanks

                            Comment

                            • Killer42
                              Recognized Expert Expert
                              • Oct 2006
                              • 8429

                              #15
                              Originally posted by jasbirs1982
                              I would like to convert 211,11,21,200.0 0 into
                              Two hundred eleven crores, eleven lakhs, twenty one thousand and two hundred only.
                              Isn't that what the code posted here already does?

                              By the way, can someone please explain "crores"? I get that a "lakh" is a hundred thousand. Is a "crore" a million, or what?

                              Comment

                              Working...