Get a Number Suffix
They allow you to turn 1 into 1st, 2 into 2nd, etc. giving your application an air of intelligence.
This code snippet accepts a regular integer and returns the number along with its appropriate suffix.
Example. Ordinal(1) ' returns 1st
Ordinal(342) ' returns 342nd
Ordinal(13) ' returns 13th
Found on the net, not my work
Public Function Ordinal(Number As Integer) As String
'Accepts an integer, returns the ordinal number
Dim strSuffix As String
If Number > 21 Then
Select Case Right(Trim(Str(Number)), 1)
Case 1
strSuffix = "st"
Case 2
strSuffix = "nd"
Case 3
strSuffix = "rd"
Case 0, 4 To 9
strSuffix = "th"
End Select
Else
Select Case Number
Case 1
strSuffix = "st"
Case 2
strSuffix = "nd"
Case 3
strSuffix = "rd"
Case 4 To 20
strSuffix = "th"
End Select
End If
Ordinal = Trim(Str(Number)) & strSuffix
End Function
'Accepts an integer, returns the ordinal number
Dim strSuffix As String
If Number > 21 Then
Select Case Right(Trim(Str(Number)), 1)
Case 1
strSuffix = "st"
Case 2
strSuffix = "nd"
Case 3
strSuffix = "rd"
Case 0, 4 To 9
strSuffix = "th"
End Select
Else
Select Case Number
Case 1
strSuffix = "st"
Case 2
strSuffix = "nd"
Case 3
strSuffix = "rd"
Case 4 To 20
strSuffix = "th"
End Select
End If
Ordinal = Trim(Str(Number)) & strSuffix
End Function
Number
Views 5,072
Downloads 1,365
CodeID
DB ID