473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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...
Feb 27 '07 #1
15 8274
vijaydiwakar
579 512MB
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
Feb 27 '07 #2
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
Feb 27 '07 #3
vijaydiwakar
579 512MB
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?
Feb 27 '07 #4
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
Feb 27 '07 #5
Here i am posting the code.this function is for converting Indian Rupees.
I think it will help u
Expand|Select|Wrap|Line Numbers
  1. '   This function will work upto 99,99,99,999.99 
  2.  
  3. Public Function convinRS(Number As Double) As String
  4.     Dim tempstr As String
  5.     Dim tempnum As Double
  6.     Dim convstr As String
  7.     Dim partlen As Byte
  8.     Dim ptat As Byte
  9.     Dim digs As Integer
  10.  
  11.  
  12.     convstr = ""
  13.     ptat = InStr(1, CStr(Number), ".")
  14.     If ptat = 0 Then
  15.         tempnum = CStr(Number)
  16.     Else
  17.         tempnum = Mid(CStr(Number), 1, ptat)
  18.     End If
  19.     tempstr = Trim(CStr(tempnum))
  20.  
  21.  
  22.     While Not tempnum = 0
  23.  
  24.         partlen = Len(tempstr)
  25.         Select Case partlen
  26.         Case Is >= 8
  27.             digs = CInt(Mid(tempstr, 1, partlen - 7))
  28.             convstr = diginwrd(digs)
  29.             If digs > 1 Then
  30.                 convstr = convstr & "Crores "
  31.             Else
  32.                 convstr = convstr & "Crore "
  33.             End If
  34.             tempstr = Right(tempstr, 7)
  35.         Case Is >= 6 And partlen < 8
  36.             digs = CInt(Mid(tempstr, 1, partlen - 5))
  37.             convstr = convstr & diginwrd(digs)
  38.             If digs > 1 Then
  39.                 convstr = convstr & "Lakhs "
  40.             Else
  41.                 convstr = convstr & "Lakh "
  42.             End If
  43.             tempstr = Right(tempstr, 5)
  44.  
  45.         Case Is < 6 And partlen >= 4
  46.             digs = CInt(Mid(tempstr, 1, partlen - 3))
  47.             convstr = convstr + diginwrd(digs)
  48.             convstr = convstr & "Thousand "
  49.             tempstr = Right(tempstr, 3)
  50.         Case Is <= 3
  51.             digs = CInt(tempstr)
  52.             convstr = convstr + diginwrd(digs)
  53.             tempstr = "0"
  54.         End Select
  55.         tempnum = CLng(tempstr)
  56.  
  57.         'MsgBox tempnum & convstr
  58.     Wend
  59.     If ptat = 0 Then
  60.         tempnum = 0
  61.     Else
  62.         tempnum = Val(Right(CStr(Number), Len(CStr(Number)) - ptat + 1)) * 100
  63.     End If
  64. '    MsgBox convstr & tempnum
  65.     convstr = "Rupees " & convstr
  66.     If Not tempnum = 0 Then
  67.         convinRS = convstr & "And " & diginwrd(tempnum) & "Paise Only"
  68.     Else
  69.         convinRS = convstr & "Only"
  70.     End If
  71. End Function
  72.  
  73. Public Function diginwrd(ByVal digsnum As Integer) As String
  74.     Select Case digsnum
  75.     Case 1
  76.         diginwrd = "One "
  77.     Case 2
  78.         diginwrd = "Two "
  79.     Case 3
  80.         diginwrd = "Three "
  81.     Case 4
  82.         diginwrd = "Four "
  83.     Case 5
  84.         diginwrd = "Five "
  85.     Case 6
  86.         diginwrd = "Six "
  87.     Case 7
  88.         diginwrd = "Seven "
  89.     Case 8
  90.         diginwrd = "Eight "
  91.     Case 9
  92.         diginwrd = "Nine "
  93.     Case 10
  94.         diginwrd = "Ten "
  95.     Case 11
  96.         diginwrd = "Eleven "
  97.     Case 12
  98.         diginwrd = "Twelve "
  99.     Case 13
  100.         diginwrd = "Thirteen "
  101.     Case 14
  102.         diginwrd = "Fourteen "
  103.     Case 15
  104.         diginwrd = "Fifteen "
  105.     Case 16
  106.         diginwrd = "Sixteen "
  107.     Case 17
  108.         diginwrd = "Seventeen "
  109.     Case 18
  110.         diginwrd = "Eighteen "
  111.     Case 19
  112.         diginwrd = "Nineteen "
  113.     Case Is > 19
  114.         Dim dig As Integer
  115.         Dim tdigword As String
  116.         Dim thdig As String
  117.         dig = CInt(Right(CStr(digsnum), 1))
  118.  
  119.         If digsnum >= 100 Then
  120.             thdig = Left(CStr(digsnum), 1)
  121.             dig = CInt(Right(CStr(digsnum), 2))
  122.         Else
  123.             dig = CInt(Right(CStr(digsnum), 1))
  124.         End If
  125.         Select Case digsnum
  126.         Case Is >= 100
  127.             tdigword = diginwrd(CInt(thdig)) & "Hundred "
  128.         Case Is >= 90 And digsnum < 100
  129.             tdigword = "Ninety "
  130.         Case Is >= 80 And digsnum < 90
  131.             tdigword = "Eighty "
  132.         Case Is >= 70 And digsnum < 80
  133.             tdigword = "Seventy "
  134.         Case Is >= 60 And digsnum < 70
  135.             tdigword = "Sixty "
  136.         Case Is >= 50 And digsnum < 60
  137.             tdigword = "Fifty "
  138.         Case Is >= 40 And digsnum < 50
  139.             tdigword = "Forty "
  140.         Case Is >= 30 And digsnum < 40
  141.             tdigword = "Thirty "
  142.         Case Is >= 20 And digsnum < 30
  143.             tdigword = "Twenty "
  144.         End Select
  145.         diginwrd = tdigword & diginwrd(dig)
  146. End Select
  147.  
  148. End Function
Feb 27 '07 #6
vijaydiwakar
579 512MB
ooo.... thnx ...it will be ok for me ..... thnx a lot again
the code
Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function NoToWord(Acceptno As Double) As String
  3.     NoToWord = ""
  4.  
  5.     Dim FormatStr As String
  6.     FormatStr = Format(Acceptno, "000000000.00")
  7.  
  8.     If Val(mid(FormatStr, 1, 2)) <> 0 Then
  9.         Call Word(Val(mid(FormatStr, 1, 2)))
  10.         NoToWord = StrConv(NoToWord & Trim(WordStr) & " CRORE ", vbProperCase)
  11.     End If
  12.     If Val(mid(FormatStr, 3, 2)) <> 0 Then
  13.         Call Word(Val(mid(FormatStr, 3, 2)))
  14.         NoToWord = StrConv(NoToWord & Trim(WordStr) & " LAC ", vbProperCase)
  15.     End If
  16.     If Val(mid(FormatStr, 5, 2)) <> 0 Then
  17.         Call Word(Val(mid(FormatStr, 5, 2)))
  18.         NoToWord = StrConv(NoToWord & Trim(WordStr) & " THOUSAND ", vbProperCase)
  19.     End If
  20.     If Val(mid(FormatStr, 7, 1)) <> 0 Then
  21.         Call Word(Val(mid(FormatStr, 7, 1)))
  22.         NoToWord = StrConv(NoToWord & Trim(WordStr) & " HUNDRED ", vbProperCase)
  23.     End If
  24.     If Val(mid(FormatStr, 8, 2)) <> 0 Then
  25.         Call Word(Val(mid(FormatStr, 8, 2)))
  26.         NoToWord = StrConv(NoToWord & Trim(WordStr) & " ", vbProperCase)
  27.     End If
  28.     If Val(mid(FormatStr, 11, 2)) <> 0 Then
  29.         Call Word(Val(mid(FormatStr, 11, 2)))
  30.         If (NoToWord <> "") Then
  31.           NoToWord = StrConv("Rs. " & NoToWord & "AND " & Trim(WordStr) & " PAISE ONLY", vbProperCase)
  32.         Else
  33.           NoToWord = StrConv(NoToWord & Trim(WordStr) & " PAISE ONLY", vbProperCase)
  34.         End If
  35.     Else
  36.        If NoToWord <> "" Then
  37.           NoToWord = StrConv("Rs. " & NoToWord + " ONLY", vbProperCase)
  38.        Else
  39.           NoToWord = "(In Words )"
  40.        End If
  41.     End If
  42. End Function
  43.  
  44. Sub Word(num As Byte)
  45.   Dim X(9) As String
  46.   Dim x1(9) As String
  47.   Dim x2(9) As String
  48.  
  49.  
  50.   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 ":
  51.   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 ":
  52.   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 ":
  53.  
  54.  
  55.   If num <= 9 Then ' for 1 to 9
  56.    WordStr = X(num)
  57.   End If
  58.   If num >= 10 Then ' for 10 to 99
  59.      If (num Mod 10 = 0) Then ' for 10,20,30....90
  60.         WordStr = x1(Int(num / 10))
  61.     End If
  62.     If (Int(num / 10) = 1 And (num Mod 10 <> 0)) Then 'for 11,12,13.....19
  63.         WordStr = x2(num Mod 10)
  64.     End If
  65.     If (Int(num / 10) > 1 And (num Mod 10 <> 0)) Then ' for 21,22,23.....99
  66.         WordStr = x1(Int(num / 10)) + X(num Mod 10)
  67.     End If
  68.   End If
  69. End Sub
  70.  
  71.  
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
Feb 27 '07 #7
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....
Feb 27 '07 #8
vijaydiwakar
579 512MB
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?
Feb 27 '07 #9
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 !!!
Feb 27 '07 #10
markmcgookin
648 Expert 512MB
the code
Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function NoToWord(Acceptno As Double) As String
  3.     NoToWord = ""
  4.  
  5.     Dim FormatStr As String
  6.     FormatStr = Format(Acceptno, "000000000.00")
  7.  
  8.     If Val(mid(FormatStr, 1, 2)) <> 0 Then
  9.         Call Word(Val(mid(FormatStr, 1, 2)))
  10.         NoToWord = StrConv(NoToWord & Trim(WordStr) & " CRORE ", vbProperCase)
  11.     End If
  12.     If Val(mid(FormatStr, 3, 2)) <> 0 Then
  13.         Call Word(Val(mid(FormatStr, 3, 2)))
  14.         NoToWord = StrConv(NoToWord & Trim(WordStr) & " LAC ", vbProperCase)
  15.     End If
  16.     If Val(mid(FormatStr, 5, 2)) <> 0 Then
  17.         Call Word(Val(mid(FormatStr, 5, 2)))
  18.         NoToWord = StrConv(NoToWord & Trim(WordStr) & " THOUSAND ", vbProperCase)
  19.     End If
  20.     If Val(mid(FormatStr, 7, 1)) <> 0 Then
  21.         Call Word(Val(mid(FormatStr, 7, 1)))
  22.         NoToWord = StrConv(NoToWord & Trim(WordStr) & " HUNDRED ", vbProperCase)
  23.     End If
  24.     If Val(mid(FormatStr, 8, 2)) <> 0 Then
  25.         Call Word(Val(mid(FormatStr, 8, 2)))
  26.         NoToWord = StrConv(NoToWord & Trim(WordStr) & " ", vbProperCase)
  27.     End If
  28.     If Val(mid(FormatStr, 11, 2)) <> 0 Then
  29.         Call Word(Val(mid(FormatStr, 11, 2)))
  30.         If (NoToWord <> "") Then
  31.           NoToWord = StrConv("Rs. " & NoToWord & "AND " & Trim(WordStr) & " PAISE ONLY", vbProperCase)
  32.         Else
  33.           NoToWord = StrConv(NoToWord & Trim(WordStr) & " PAISE ONLY", vbProperCase)
  34.         End If
  35.     Else
  36.        If NoToWord <> "" Then
  37.           NoToWord = StrConv("Rs. " & NoToWord + " ONLY", vbProperCase)
  38.        Else
  39.           NoToWord = "(In Words )"
  40.        End If
  41.     End If
  42. End Function
  43.  
  44. Sub Word(num As Byte)
  45.   Dim X(9) As String
  46.   Dim x1(9) As String
  47.   Dim x2(9) As String
  48.  
  49.  
  50.   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 ":
  51.   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 ":
  52.   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 ":
  53.  
  54.  
  55.   If num <= 9 Then ' for 1 to 9
  56.    WordStr = X(num)
  57.   End If
  58.   If num >= 10 Then ' for 10 to 99
  59.      If (num Mod 10 = 0) Then ' for 10,20,30....90
  60.         WordStr = x1(Int(num / 10))
  61.     End If
  62.     If (Int(num / 10) = 1 And (num Mod 10 <> 0)) Then 'for 11,12,13.....19
  63.         WordStr = x2(num Mod 10)
  64.     End If
  65.     If (Int(num / 10) > 1 And (num Mod 10 <> 0)) Then ' for 21,22,23.....99
  66.         WordStr = x1(Int(num / 10)) + X(num Mod 10)
  67.     End If
  68.   End If
  69. End Sub
  70.  
  71.  
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 ^.^
Feb 27 '07 #11
vijaydiwakar
579 512MB
Kudos on a great reply. I'd have just left it saying 551 ^.^
would u pls explan 551 pls
Feb 27 '07 #12
markmcgookin
648 Expert 512MB
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)
Feb 27 '07 #13
Hi,

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

please help

thanks
Mar 6 '08 #14
Killer42
8,435 Expert 8TB
I would like to convert 211,11,21,200.00 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?
Mar 7 '08 #15
Killer42
8,435 Expert 8TB
I would like to convert 211,11,21,200 ...
Something I forgot to ask before, but potentially important. Is this a typo, or does your country group digits this way (3 digits, then 2, then 2, then 3)? If so, this could impact greatly on any code which formats numbers or interprets formatted numbers (or does anything based on calculating the length of formatted numbers). I had always assumed that everyone grouped digits 3 at a time, the way we do (eg. 2,111,121,200) but it certainly wouldn't be the first time I've been wrong.

It's also potentially a very interesting piece of trivia. :)
Mar 25 '08 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
3
by: Eitan | last post by:
Hello, I am looking for a function which convert hebrew string (windows) to hebrew string (dos). That's should pay attantion to commas, numbers, and any other character, that may have problem...
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
7
by: shellon | last post by:
Hi all: I want to convert the float number to sortable integer, like the function float2rawInt() in java, but I don't know the internal expression of float, appreciate your help!
17
by: Ron | last post by:
I want to write a program that will accept a number in a textbox for example 23578 and then in a label will display the sum of the odd and even number like this... the textbox containsthe number...
8
by: =?Utf-8?B?UmljYXJkbyBRdWludGFuaWxsYQ==?= | last post by:
i need to convert data from string to nibble wich (nibble is a four bits representation) As example i have the following code string data1 = "12345678"; so ¿how can i convert this data...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.