473,396 Members | 2,052 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,396 software developers and data experts.

How to Convert Age or Date of Birth from Digits to Words?

58 32bit
i am beginner dont understand coding very well, i saw a post in which i get code but i dont know it will work or now and i dont know how to use it in VBA. can anybody teach me ?
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Sub Test()
  5. Dim TestDate As Date
  6.     TestDate = CDate("11.04.2013")
  7. Dim dtString As String
  8.     dtString = DateInWords(TestDate)
  9.  
  10.     MsgBox (dtString)
  11. End Sub
  12.  
  13. Function DateInWords(dt As Date) As String
  14. Dim strDays As String, SplitDays
  15.     strDays = _
  16.         "Day_1,Day_2,Day_3,Day_4,Day_5,Day_6,Day_7," & _
  17.         "Day_8,Day_9,Day_10,Day_11,Day_12,Day_13,Day_14," & _
  18.         "Day_15,Day_16,Day_17,Day_18,Day_19,Day_20,Day_21," & _
  19.         "Day_22,Day_23,Day_24,Day_25,Day_26,Day_27,Day_28," & _
  20.         "Day_29,Day_30,Day_31"
  21.     SplitDays = Split(strDays, ",")
  22. Dim strMothes As String, SplitMonthes
  23.     strMothes = _
  24.         "Month_1,Month_2,Month_3,Month_4,Month_5,Month_6," & _
  25.         "Month_7,Month_8,Month_9,Month_10,Month_11,Month_12"
  26.     SplitMonthes = Split(strMothes, ",")
  27. Dim strYears As String, SplitYears
  28.     strYears = _
  29.         "Year_2010,Year_2011,Year_2012,Year_2013," & _
  30.         "Year_2014,Year_2015,Year_2016,Year_2017," & _
  31.         "Year_2018,Year_2019,Year_2020"
  32.     SplitYears = Split(strYears, ",")
  33.  
  34. Dim strDay As String
  35.     strDay = SplitDays(Day(dt) - 1)
  36. Dim strMonth As String
  37.     strMonth = SplitMonthes(Month(dt) - 1)
  38. Dim strYear As String
  39.     strYear = SplitYears(Year(dt) - 2010)
  40.  
  41.     DateInWords = strDay & " " & strMonth & ", " & strYear
  42. End Function
Aug 3 '20 #1
6 3176
SioSio
272 256MB
Line #5
When using CDate, separate the year, month, and day of the date with a slash. Or write # before and after the date without using CDate.
Expand|Select|Wrap|Line Numbers
  1. TestDate = CDate("11/04/2013")
or
Expand|Select|Wrap|Line Numbers
  1. TestDate = #11/4/2013#
Aug 3 '20 #2
ZKAHADI
58 32bit
Brother i am asking about how to convert Date digits into Words like 1/1/2012 to First January Two Thousand Two
Aug 3 '20 #3
SioSio
272 256MB
Only the date conversion has adopted your way.
The Month is converted by the Format function, and the year is modified by the SpellNumber function provided by M.S.

Expand|Select|Wrap|Line Numbers
  1. Sub Test()
  2. Dim TestDate As Date
  3. TestDate = CDate("11/04/2013")
  4. Dim dtString As String
  5. dtString = DateInWords(TestDate)
  6. MsgBox (dtString)
  7. End Sub
  8.  
  9.  
  10. Function DateInWords(dt As Date) As String
  11. Dim strDays As String, SplitDays
  12. strDays = "first,second,third,fourth,fifth," & _
  13.     "sixth,seventh,eighth,ninth,tenth,11th,12th," & _
  14.     "13th,14th,15th,16th,17th,18th,19th,20th," & _
  15.     "21st,22nd,23rd,24th,25th,26th,27th,28th," & _
  16.     "29th,30th,31th"
  17. SplitDays = Split(strDays, ",")
  18.  
  19. Dim strDay As String
  20. strDay = SplitDays(Day(dt) - 1)
  21.  
  22. Dim strMonth As String
  23. strMonth = Format(dt, "mmmm")
  24.  
  25. Dim strYear As String
  26.  
  27. Dim intYear As Integer
  28. Dim yyyy, y1, y2, y3 As Integer
  29. strYear = Format(dt, "yyyy")
  30.  
  31. strYear = SpellNumber(strYear)
  32.  
  33. DateInWords = strDay & " " & strMonth & ", " & strYear
  34. End Function
  35.  
  36.  
  37. Function SpellNumber(MyNumber)
  38. Dim Dollars, Cents, Temp
  39. Dim DecimalPlace, Count
  40. ReDim Place(9) As String
  41. Place(2) = " Thousand "
  42. Place(3) = " Million "
  43. Place(4) = " Billion "
  44. Place(5) = " Trillion "
  45.  
  46. ' String representation of amount.
  47.  
  48. MyNumber = Trim(Str(MyNumber))
  49. ' Position of decimal place 0 if none.
  50. DecimalPlace = InStr(MyNumber, ".")
  51. Count = 1
  52. Do While MyNumber <> ""
  53. Temp = GetHundreds(Right(MyNumber, 3))
  54. If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
  55. If Len(MyNumber) > 3 Then
  56. MyNumber = Left(MyNumber, Len(MyNumber) - 3)
  57. Else
  58. MyNumber = ""
  59. End If
  60. Count = Count + 1
  61. Loop
  62. SpellNumber = Dollars & Cents
  63. End Function
  64.  
  65. ' Converts a number from 100-999 into text
  66. Function GetHundreds(ByVal MyNumber)
  67. Dim Result As String
  68. If Val(MyNumber) = 0 Then Exit Function
  69. MyNumber = Right("000" & MyNumber, 3)
  70. ' Convert the hundreds place.
  71. If Mid(MyNumber, 1, 1) <> "0" Then
  72. Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
  73. End If
  74.  
  75. ' Convert the tens and ones place.
  76. If Mid(MyNumber, 2, 1) <> "0" Then
  77. Result = Result & GetTens(Mid(MyNumber, 2))
  78. Else
  79. Result = Result & GetDigit(Mid(MyNumber, 3))
  80. End If
  81. GetHundreds = Result
  82. End Function
  83.  
  84. ' Converts a number from 10 to 99 into text.
  85. Function GetTens(TensText)
  86. Dim Result As String
  87. Result = "" ' Null out the temporary function value.
  88. If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
  89. Select Case Val(TensText)
  90. Case 10: Result = "Ten"
  91. Case 11: Result = "Eleven"
  92. Case 12: Result = "Twelve"
  93. Case 13: Result = "Thirteen"
  94. Case 14: Result = "Fourteen"
  95. Case 15: Result = "Fifteen"
  96. Case 16: Result = "Sixteen"
  97. Case 17: Result = "Seventeen"
  98. Case 18: Result = "Eighteen"
  99. Case 19: Result = "Nineteen"
  100. Case Else
  101. End Select
  102. Else ' If value between 20-99...
  103. Select Case Val(Left(TensText, 1))
  104. Case 2: Result = "Twenty "
  105. Case 3: Result = "Thirty "
  106. Case 4: Result = "Forty "
  107. Case 5: Result = "Fifty "
  108. Case 6: Result = "Sixty "
  109. Case 7: Result = "Seventy "
  110. Case 8: Result = "Eighty "
  111. Case 9: Result = "Ninety "
  112. Case Else
  113. End Select
  114. Result = Result & GetDigit(Right(TensText, 1)) ' Retrieve ones place.
  115. End If
  116. GetTens = Result
  117. End Function
  118.  
  119.  
  120. ' Converts a number from 1 to 9 into text.
  121.  
  122. Function GetDigit(Digit)
  123. Select Case Val(Digit)
  124. Case 1: GetDigit = "One"
  125. Case 2: GetDigit = "Two"
  126. Case 3: GetDigit = "Three"
  127. Case 4: GetDigit = "Four"
  128. Case 5: GetDigit = "Five"
  129. Case 6: GetDigit = "Six"
  130. Case 7: GetDigit = "Seven"
  131. Case 8: GetDigit = "Eight"
  132. Case 9: GetDigit = "Nine"
  133. Case Else: GetDigit = ""
  134. End Select
  135. End Function
  136.  
Aug 3 '20 #4
ZKAHADI
58 32bit
yea i need this kind of code. now please last time tell me where i use this code what shold i do first make a table with text boxdate and date in words then make form and where use this code in vba in class module oron date in words textbox?
Aug 3 '20 #5
NeoPa
32,556 Expert Mod 16PB
I think I should jump in here to clarify what is expected, and even what is acceptable, for those who may not have read our very prominent guidelines.

This question is answered and it is not acceptable to allow it to meander on with further questions - related or otherwise.

This forum is for asking questions. It is not for hand-holding or for others to do work for you. Some users may decide to give further support than what is generally expected but that should never be assumed.

While those entirely new to the subject are welcome, they are expected to put the work in to progress from that so that they can understand both the questions and the answers. Where possible we encourage all our experts to give clear answers and to pitch it easily for newbies if required, but still the member has to be able to understand the basics. That is their responsibility, not the experts'.

It is easy to find many tutorials, and even very reasonably priced tutors, after a quick search so please understand this is not somewhere to come to allow others to do your work for you. You have to show at least as much effort as those assisting, and it should be more - except as you can see many of our experts do put a lot of effort into trying to help you so that bar's quite high.

As far as this thread goes the single question has been answered and further meandering will not be allowed.
Aug 3 '20 #6
ZKAHADI
58 32bit
never mind Neopa and Thanks SioSio this code working and i learned using thanks you very very much.
Aug 4 '20 #7

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

Similar topics

4
by: Gerry | last post by:
As I'm not a PHP-prgrammer at all, I just need Help with this: I have had a guestbook-page in Europe and will now have to move it to a US based-server. This makes the time-function showing time...
1
by: Rowlie | last post by:
Hi I am very new to access. I am starting a new job and have been asked to design a data base. After much messing around I have got something that is just o.k. The problem is that every time I...
1
by: tomerslider | last post by:
i need some code that show me all the expired product that i have in every month example: the date today is 4/11/05 i need that it will show me all the proudct that there dates betwenn 1/11/05...
5
by: manmit.walia | last post by:
Hello All, I am stuck on a conversion problem. I am trying to convert my application which is written in VB.NET to C# because the project I am working on currently is being written in C#. I tried...
7
by: erekose666 | last post by:
I need a java prog to do the following: Create class Date with the following capabilities: a) Output the date in multiple formats, such as: MM/DD/YYYY June 14, 2005 DDD YYYY b) Use...
4
by: kirku | last post by:
any body please help me.. i wants to add months to a fixed date... ie i wants to add 2 month to 2007-05-18 .. pls help...
19
by: eskelies | last post by:
I have two queries. My goal is to pull a range of numbers that fall on or in a certain date range. For example, $100 on 9/1/2007 and $200 on 9/24/2007. I want the date range to pick up both the...
8
by: sweetfee | last post by:
I'm New To Access. I Have A Form That Has The Date That The Customer Membership Fee Is Due If The Fee Isn't Pd By This Date I Would Like The Label Visible Showing The Text 'overdue' Help Please
5
by: Phien-An Nguyen | last post by:
Hello, I have a TextBox1 binds to dateEnterred as datetime. My system date format is m/d/yy. When I gave the value as string, "04/18/2008" to the TextBox1.Text, it changed to "41/8/08". ...
15
by: jayjayplane | last post by:
Currently I use Access form/subform to design a database interface, one field is date type field, but I need if the user inputs the future date like later than system currently date, I want it pop up...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.