473,434 Members | 1,829 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,434 software developers and data experts.

How to Get Students' Results in Ordinal Form (1st, 2nd, 3rd etc)

How can i create 1st, 2nd, 3rd e.t.c numbers in Microsoft access when my numbers are appearing in text boxes ?
Nov 24 '17 #1
6 2593
Luuk
1,047 Expert 1GB
Someone solved this problem for you a while a go, and mentioned:
"Hope it's useful for someone.!"

i also post his code here:
Expand|Select|Wrap|Line Numbers
  1. Public  Function IntToOrdinalString(MyNumber As Integer) As String
  2.     Dim sOutput As String
  3.     Dim iUnit As Integer
  4.  
  5.  
  6.     iUnit = MyNumber Mod 10
  7.     sOutput = ""
  8.  
  9.     Select Case MyNumber
  10.         Case Is < 0
  11.             sOutput = ""
  12.         Case 10 To 19
  13.             sOutput = "th"
  14.         Case Else
  15.             Select Case iUnit
  16.                 Case 0 'Zeroth only has a meaning when counts start with zero, which happens in a mathematical or computer science context.
  17.                     sOutput = "th"
  18.                 Case 1
  19.                     sOutput = "st"
  20.                 Case 2
  21.                     sOutput = "nd"
  22.                 Case 3
  23.                     sOutput = "rd"
  24.                 Case 4 To 9
  25.                     sOutput = "th"
  26.             End Select
  27.     End Select
  28.     IntToOrdinalString = CStr(MyNumber) & sOutput
  29. End Function
Nov 24 '17 #2
Narender Sagar
189 100+
If you already have numbers (1, 2, 3..) in a column, then a simple solution can be.. just create a separate table wherein you can maintain two fields such as 'Number' and 'Ordinal Text' (numbers and their ordinal form-like 1st, 2nd etc.). Simply join these two tables in a query and you can get the desired result wherever you want.
Dec 5 '17 #3
Luuk
1,047 Expert 1GB
A user-defined function would be better to get this job donem because it's very static data we are taling about.

Expand|Select|Wrap|Line Numbers
  1. Function OrdinalSuffix(ByVal Num As Long) As String
  2.         Dim N As Long
  3.         Const cSfx = "stndrdthththththth" ' 2 char suffixes
  4.         N = Num Mod 100
  5.         If ((Abs(N) >= 10) And (Abs(N) <= 19)) _
  6.                 Or ((Abs(N) Mod 10) = 0) Then
  7.             OrdinalSuffix = "th"
  8.         Else
  9.             OrdinalSuffix = Mid(cSfx, _
  10.                 ((Abs(N) Mod 10) * 2) - 1, 2)
  11.         End If
  12.     End Function
  13.  
Dec 5 '17 #4
NeoPa
32,556 Expert Mod 16PB
Interesting solution by Luuk. I agree that's a far better way to handle numbers whose limits you don't know (How big would the table need to be to handle an infinite set of integers??)

While the code is also quite elegant it might be improved :
Expand|Select|Wrap|Line Numbers
  1. Private Const conSuffix As String = "stndrdthththththth"
  2.  
  3. Public Function OrdinalSuffix(ByVal lngVal As Long) As String
  4.     lngVal = Abs(lngVal) Mod 100
  5.     If (lngVal = 0) _
  6.     Or (lngVal Between 4 And 20) Then
  7.         OrdinalSuffix = "th"
  8.     Else
  9.         OrdinalSuffix = Mid(conSuffix, (lngVal Mod 10) * 2 - 1, 2)
  10.     End If
  11. End Function
Dec 6 '17 #5
Luuk
1,047 Expert 1GB
I had to mention the fact that the code was found on the internet (^1).
But some guys change my posts and the delete the link... ;)

Removed link again. Link was to assign credit to Chip Pearson where the original code was found.
Dec 6 '17 #6
NeoPa
32,556 Expert Mod 16PB
Yes Luuk.

That guy was me and I've done it again as it's against the rules of the site to post a link to competing resources. It's called leeching and you'll find that's illegal on most forum sites you visit. As one of the moderators it's my responsibility to remove such links as and when I find them and direct the member posting them so they understand not to repeat the behaviour in future.

This is no reflection on Chip Pearson who provides a lot of good resources for Access, but I think most intelligent people will understand why leeching is unhelpful for a forum site to be able to do what it does - which ultimately is to help those who need help with Access.

Nevertheless, it was an example of some clever code and you did well to select and post it. We can all see that you attributed credit where it was due.
Dec 7 '17 #7

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

Similar topics

8
by: Adam | last post by:
Hi, I am trying to mark consective numbers in a data set and get a count as to how many consecutive numbers exist in the a given line of data. Here is an example line: 3, 5, 7, 9, 10, 13,...
2
by: Flavio | last post by:
Hi, I'm used in MS Access on Doing Queries based on Queries. Now that I'm dealling a lot with large ammount of data I think this procedure with an SQL Server back-end is falling a little bit...
3
by: Shailesh Humbad | last post by:
I figured out what was causing the "Access is Denied" error when calling functions from referenced DLLs in my service. I've tried to be very detailed, so bear with me. It turns out that...
4
by: Konrad Hammerer | last post by:
Hi! I have the following problem: I have a query (a) using another query (b) to get the amount of records of this other query (b), means: select count(MNR) as Number from...
1
by: Manners | last post by:
Hi! I am a VBA newbie, and cant seem to proceed past my current problem. I have a large query, where I need to output a select query based on the parameter set by the do loop. The do loop is...
1
by: abhishekdhal | last post by:
I want to create a form which is linked to a table.I want to have an extra field "search" so that I can find the desired person...the search textfield will have a corresponding button in it so that...
5
Cintury
by: Cintury | last post by:
I have the function that returns a numerical value according to its corresponding weekday in one column in the design view of access and what I do not know how to do is make this be "equal to" the...
2
by: kolly | last post by:
I am developing a web application for a school that will allow them to register student and computed, and print students result. I am done with calculating the result but the only thing remain for me...
5
by: Linish Francis | last post by:
In a program which adds two numbers of integer data type and prints the result, numbers greater than 32767 can neither be given as input nor obtained as output. for eg: if the operends are a and...
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
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
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
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.