473,473 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Converting number to Word..

anukagni
53 New Member
Hi friends,

I want to get this thing happen..
I want to convert the number to word i.e. if i entry 1 in an text box then it should give the reflect to One in an lable ..

Is this possible i have gone through the forum i got some result .But it is not understandable please give me clear step by step explanation .This is my humble request..

Thanks
anukagni
Jan 29 '07 #1
7 4450
NeoPa
32,556 Recognized Expert Moderator MVP
I don't know a way of doing this, but if you have a link that may explain, post it here and we can see if it makes sense to us. If so we can try to explain it for you or help you to implement it.
Jan 30 '07 #2
ADezii
8,834 Recognized Expert Expert
Hi friends,

I want to get this thing happen..
I want to convert the number to word i.e. if i entry 1 in an text box then it should give the reflect to One in an lable ..

Is this possible i have gone through the forum i got some result .But it is not understandable please give me clear step by step explanation .This is my humble request..

Thanks
anukagni
Create a simple Table (tblConversions) consisting of just 2 Fields e.g.
__Number - Long Integer (contains the actual Numeric values)
__Conversion - Text (contains the Word equivalents)

Number-----Conversion
1--------------One
2--------------Two
34------------Thirty Four
157-----------One Hundred and Fifty Seven
1916---------One Thousand Nine Hundred Sixteen

Expand|Select|Wrap|Line Numbers
  1. 'Use the DLookup Function to find the Word equivalents
  2. DLookup("[Conversion]", "tblConversions","[Number]=" & CInt(Me![txtNumber]))
Jan 30 '07 #3
missinglinq
3,532 Recognized Expert Specialist
From the Access Object Dialog Box click on "Modules"
Click on new to make a new module
Copy then paste the following code into the new module:

Expand|Select|Wrap|Line Numbers
  1. '################## Beginning of Code #######################
  2. Function SayNo(ByVal N As Currency) As String
  3.  
  4.     Const Thousand = 1000@
  5.     Const Million = Thousand * Thousand
  6.     Const Billion = Thousand * Million
  7.     Const Trillion = Thousand * Billion
  8.  
  9.     If (N = 0@) Then SayNo = "zero": Exit Function
  10.  
  11.     Dim Buf As String: If (N < 0@) Then Buf = "negative " Else Buf = ""
  12.     Dim Frac As Currency: Frac = Abs(N - Fix(N))
  13.     If (N < 0@ Or Frac <> 0@) Then N = Abs(Fix(N))
  14.     Dim AtLeastOne As Integer: AtLeastOne = N >= 1
  15.  
  16.     If (N >= Trillion) Then
  17.         Debug.Print N
  18.         Buf = Buf & SayNoDigitGroup(Int(N / Trillion)) & " trillion"
  19.         N = N - Int(N / Trillion) * Trillion
  20.         If (N >= 1@) Then Buf = Buf & " "
  21.     End If
  22.  
  23.     If (N >= Billion) Then
  24.         Debug.Print N
  25.         Buf = Buf & SayNoDigitGroup(Int(N / Billion)) & " billion"
  26.         N = N - Int(N / Billion) * Billion
  27.         If (N >= 1@) Then Buf = Buf & " "
  28.     End If
  29.  
  30.     If (N >= Million) Then
  31.         Debug.Print N
  32.         Buf = Buf & SayNoDigitGroup(N \ Million) & " million"
  33.         N = N Mod Million
  34.         If (N >= 1@) Then Buf = Buf & " "
  35.     End If
  36.  
  37.     If (N >= Thousand) Then
  38.         Debug.Print N
  39.         Buf = Buf & SayNoDigitGroup(N \ Thousand) & " thousand"
  40.         N = N Mod Thousand
  41.         If (N >= 1@) Then Buf = Buf & " "
  42.     End If
  43.  
  44.     If (N >= 1@) Then
  45.         Debug.Print N
  46.         Buf = Buf & SayNoDigitGroup(N)
  47.     End If
  48.  
  49.     If (Frac = 0@) Then
  50.         Buf = Buf
  51.     ElseIf (Int(Frac * 100@) = Frac * 100@) Then
  52.         If AtLeastOne Then Buf = Buf & " and "
  53.         Buf = Buf & Format$(Frac * 100@, "00") & "/100"
  54.     Else
  55.         If AtLeastOne Then Buf = Buf & " and "
  56.         Buf = Buf & Format$(Frac * 10000@, "0000") & "/10000"
  57.     End If
  58.  
  59.     SayNo = Buf
  60. End Function
  61.  
  62. Private Function SayNoDigitGroup(ByVal N As Integer) As String
  63.  
  64.     Const Hundred = " hundred"
  65.     Const One = "one"
  66.     Const Two = "two"
  67.     Const Three = "three"
  68.     Const Four = "four"
  69.     Const Five = "five"
  70.     Const Six = "six"
  71.     Const Seven = "seven"
  72.     Const Eight = "eight"
  73.     Const Nine = "nine"
  74.     Dim Buf As String: Buf = ""
  75.     Dim Flag As Integer: Flag = False
  76.  
  77.     Select Case (N \ 100)
  78.         Case 0: Buf = "": Flag = False
  79.         Case 1: Buf = One & Hundred: Flag = True
  80.         Case 2: Buf = Two & Hundred: Flag = True
  81.         Case 3: Buf = Three & Hundred: Flag = True
  82.         Case 4: Buf = Four & Hundred: Flag = True
  83.         Case 5: Buf = Five & Hundred: Flag = True
  84.         Case 6: Buf = Six & Hundred: Flag = True
  85.         Case 7: Buf = Seven & Hundred: Flag = True
  86.         Case 8: Buf = Eight & Hundred: Flag = True
  87.         Case 9: Buf = Nine & Hundred: Flag = True
  88.     End Select
  89.  
  90.     If (Flag <> False) Then N = N Mod 100
  91.     If (N > 0) Then
  92.         If (Flag <> False) Then Buf = Buf & " "
  93.     Else
  94.         SayNoDigitGroup = Buf
  95.         Exit Function
  96.     End If
  97.  
  98.     Select Case (N \ 10)
  99.         Case 0, 1: Flag = False
  100.         Case 2: Buf = Buf & "twenty": Flag = True
  101.         Case 3: Buf = Buf & "thirty": Flag = True
  102.         Case 4: Buf = Buf & "forty": Flag = True
  103.         Case 5: Buf = Buf & "fifty": Flag = True
  104.         Case 6: Buf = Buf & "sixty": Flag = True
  105.         Case 7: Buf = Buf & "seventy": Flag = True
  106.         Case 8: Buf = Buf & "eighty": Flag = True
  107.         Case 9: Buf = Buf & "ninety": Flag = True
  108.     End Select
  109.  
  110.     If (Flag <> False) Then N = N Mod 10
  111.     If (N > 0) Then
  112.         If (Flag <> False) Then Buf = Buf & "-"
  113.     Else
  114.         SayNoDigitGroup = Buf
  115.         Exit Function
  116.     End If
  117.  
  118.     Select Case (N)
  119.         Case 0:
  120.         Case 1: Buf = Buf & One
  121.         Case 2: Buf = Buf & Two
  122.         Case 3: Buf = Buf & Three
  123.         Case 4: Buf = Buf & Four
  124.         Case 5: Buf = Buf & Five
  125.         Case 6: Buf = Buf & Six
  126.         Case 7: Buf = Buf & Seven
  127.         Case 8: Buf = Buf & Eight
  128.         Case 9: Buf = Buf & Nine
  129.         Case 10: Buf = Buf & "ten"
  130.         Case 11: Buf = Buf & "eleven"
  131.         Case 12: Buf = Buf & "twelve"
  132.         Case 13: Buf = Buf & "thirteen"
  133.         Case 14: Buf = Buf & "fourteen"
  134.         Case 15: Buf = Buf & "fifteen"
  135.         Case 16: Buf = Buf & "sixteen"
  136.         Case 17: Buf = Buf & "seventeen"
  137.         Case 18: Buf = Buf & "eighteen"
  138.         Case 19: Buf = Buf & "nineteen"
  139.     End Select
  140.  
  141.     SayNoDigitGroup = Buf
  142.  
  143. End Function
  144.  
  145. '############# End of Code #########################
  146.  
Save the module and call it, say, NumbersToWords

Now from your form call the function using the syntax

SayNo(YourNumericalValue)

As an example (since I don't know your skill level, sorry) here's what I did to test it. After doing the above to create the module, I ran up a simple form with a textbox and a label; txtTextNumbers and lblTextWords

Private Sub txtTextNumbers_Exit(Cancel As Integer)
Me.lblTextWords.Caption = SayNo(Me.txtTextNumbers.Value)
End Sub

After entering your data and exiting the textbox the label will contain the word equivelent of the number entered.

The same code can be used in other events, of course.

The author is only known to me as M8KWR.
Jan 30 '07 #4
anukagni
53 New Member
Thanks i got the answer ..

then when i give 10.50 the it show ten and 50/100 but i really want ten and fifty
is it possible....:)

thanks
anukagni
Feb 2 '07 #5
NeoPa
32,556 Recognized Expert Moderator MVP
So this is for a Currency value?
Why did you not explain this in the question :confused:
Feb 2 '07 #6
anukagni
53 New Member
So this is for a Currency value?
Why did you not explain this in the question :confused:

the currency which define to be my countries money ...explain me what the code to get the desire value in the label
Feb 3 '07 #7
Mamunul
5 New Member
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Private Function NumToText(dblVal As Double) As String
  4.     Static Ones(0 To 9) As String
  5.     Static Teens(0 To 9) As String
  6.     Static Tens(0 To 9) As String
  7.     Static Thousands(0 To 4) As String
  8.     Static bInit As Boolean
  9.     Dim i As Integer, bAllZeros As Boolean, bShowThousands As Boolean
  10.     Dim strVal As String, strBuff As String, strTemp As String
  11.     Dim nCol As Integer, nChar As Integer
  12.  
  13.     'Only handles positive values
  14.  Debug.Print dblVal >= 0
  15.  
  16.     If bInit = False Then
  17.         'Initialize array
  18.         bInit = True
  19.         Ones(0) = "zero"
  20.         Ones(1) = "one"
  21.         Ones(2) = "two"
  22.         Ones(3) = "three"
  23.         Ones(4) = "four"
  24.         Ones(5) = "five"
  25.         Ones(6) = "six"
  26.         Ones(7) = "seven"
  27.         Ones(8) = "eight"
  28.         Ones(9) = "nine"
  29.         Teens(0) = "ten"
  30.         Teens(1) = "eleven"
  31.         Teens(2) = "twelve"
  32.         Teens(3) = "thirteen"
  33.         Teens(4) = "fourteen"
  34.         Teens(5) = "fifteen"
  35.         Teens(6) = "sixteen"
  36.         Teens(7) = "seventeen"
  37.         Teens(8) = "eighteen"
  38.         Teens(9) = "nineteen"
  39.         Tens(0) = ""
  40.         Tens(1) = "ten"
  41.         Tens(2) = "twenty"
  42.         Tens(3) = "thirty"
  43.         Tens(4) = "forty"
  44.         Tens(5) = "fifty"
  45.         Tens(6) = "sixty"
  46.         Tens(7) = "seventy"
  47.         Tens(8) = "eighty"
  48.         Tens(9) = "ninety"
  49.         Thousands(0) = ""
  50.         Thousands(1) = "thousand"   'US numbering
  51.         Thousands(2) = "million"
  52.         Thousands(3) = "billion"
  53.         Thousands(4) = "trillion"
  54.     End If
  55.     'Trap errors
  56.     On Error GoTo NumToTextError
  57.         'Convert rest to string and process each digit
  58.     strVal = CStr(Int(dblVal))
  59.     'Non-zero digit not yet encountered
  60.     bAllZeros = True
  61.     'Iterate through string
  62.     For i = Len(strVal) To 1 Step -1
  63.         'Get value of this digit
  64.         nChar = Val(Mid$(strVal, i, 1))
  65.         'Get column position
  66.         nCol = (Len(strVal) - i) + 1
  67.         'Action depends on 1's, 10's or 100's column
  68.         Select Case (nCol Mod 3)
  69.             Case 1  '1's position
  70.                 bShowThousands = True
  71.                 If i = 1 Then
  72.                     'First digit in number (last in loop)
  73.                     strTemp = Ones(nChar) & " "
  74.                 ElseIf Mid$(strVal, i - 1, 1) = "1" Then
  75.                     'This digit is part of "teen" number
  76.                     strTemp = Teens(nChar) & " "
  77.                     i = i - 1   'Skip tens position
  78.                 ElseIf nChar > 0 Then
  79.                     'Any non-zero digit
  80.                     strTemp = Ones(nChar) & " "
  81.                 Else
  82.                     'This digit is zero. If digit in tens and hundreds column
  83.                     'are also zero, don't show "thousands"
  84.                     bShowThousands = False
  85.                     'Test for non-zero digit in this grouping
  86.                     If Mid$(strVal, i - 1, 1) <> "0" Then
  87.                         bShowThousands = True
  88.                     ElseIf i > 2 Then
  89.                         If Mid$(strVal, i - 2, 1) <> "0" Then
  90.                             bShowThousands = True
  91.                         End If
  92.                     End If
  93.                     strTemp = ""
  94.                 End If
  95.                 'Show "thousands" if non-zero in grouping
  96.                 If bShowThousands Then
  97.                     If nCol > 1 Then
  98.                         strTemp = strTemp & Thousands(nCol \ 3)
  99.                         If bAllZeros Then
  100.                             strTemp = strTemp & " "
  101.                         Else
  102.                             strTemp = strTemp & ", "
  103.                         End If
  104.                     End If
  105.                     'Indicate non-zero digit encountered
  106.                     bAllZeros = False
  107.                 End If
  108.                 strBuff = strTemp & strBuff
  109.             Case 2  '10's position
  110.                 If nChar > 0 Then
  111.                     If Mid$(strVal, i + 1, 1) <> "0" Then
  112.                         strBuff = Tens(nChar) & "-" & strBuff
  113.                     Else
  114.                         strBuff = Tens(nChar) & " " & strBuff
  115.                     End If
  116.                 End If
  117.             Case 0  '100's position
  118.                 If nChar > 0 Then
  119.                     strBuff = Ones(nChar) & " hundred " & strBuff
  120.                 End If
  121.         End Select
  122.     Next i
  123.     'Convert first letter to upper case
  124.     strBuff = UCase$(Left$(strBuff, 1)) & Mid$(strBuff, 2)
  125. EndNumToText:
  126.     'Return result
  127.    NumToText = strBuff
  128.     Exit Function
  129. NumToTextError:
  130.     strBuff = "#Error#"
  131.     Resume EndNumToText
  132. End Function
  133.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2.  
  3. End Sub
  4.  
Expand|Select|Wrap|Line Numbers
  1. Private Sub PageFooter_Format(Cancel As Integer, FormatCount As Integer)
  2. If [DIVN] <> 0 Then
  3. [intitext] = NumToText(Val([intig])) & "Only"
  4. Else
  5. [intitext] = "ZERO"
  6. End If
  7. End Sub
  8.  
================================================== ====

Hi friends,

I want to get this thing happen..
I want to convert the number to word i.e. if i entry 1 in an text box then it should give the reflect to One in an lable ..

Is this possible i have gone through the forum i got some result .But it is not understandable please give me clear step by step explanation .This is my humble request..

Thanks
anukagni
Feb 3 '07 #8

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

Similar topics

0
by: Dan Stromberg | last post by:
I've written up a page about how to convert native binary data to another platform's native binary data, as I did some fortran data conversions for a client. The programs and documentation are...
20
by: Al Moritz | last post by:
Hi all, I was always told that the conversion of Word files to HTML as done by Word itself sucks - you get a lot of unnecessary code that can influence the design on web browsers other than...
11
by: Chris Online | last post by:
Hi all, I'm using C++ Builder5. I want to get data from an edit-box and send it to a development kit. The dev-kit can only receive char and no char* here's a part of my code: char* Data_byte...
8
by: prabha | last post by:
Hello Everybody, I have to conert the word doc to multiple html files,according to the templates in the word doc. I had converted the word to xml.Also through Exsl ,had finished the multiple...
2
by: Asbjørn Ulsberg | last post by:
Hi. I'm trying to convert Brady Hegberg's great RTF2HTML VB 6.0 module to C#. I've managed to convert the VB code to VB.NET, which gave me the following code: Option Strict On Option...
7
by: Converting Numeric to a word | last post by:
Hi, I have little experience in C#, Can anyone help me with this sproblem. " I want to convert a given number in a text to a word on a lable" for eg if we type 25 in text box , i want to display it...
12
by: AMP | last post by:
Hello, I have in c: WORD calcChecksum(BYTE data, WORD length) { WORD* i_data; WORD checksum= 0; BYTE i= 0; i_data= (WORD*)data;
1
by: danmilkman | last post by:
Hi Y'all Can someone help me convert the next few lines of code from c++ to c#? I've given it a try myself but my program keeps crashing when I use my c# code. I think the difficulty lies in...
1
by: ganesh22 | last post by:
Hi, Iam getting the below error while my application is running on IIS. in my application iam converting a text into word format, so i added some .dll from COM for converting word format ...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.