Search Tools Links Login

Format Fancy Number (##st, ##nd, ##rd, ##th)

Visual Basic 6, or VB Classic

This function adds st, nd, rd, or th to the end of a string of numbers based on what the number is. For example, the following code can produce the following output, "Thursday, November 23rd, 2000" : Format(Date, "dddd, mmmm ") & FormatFancyNumber(Day(Date)) & ", " & Year(Date)

Original Author: Alex Nunn


All this function needs is an integer number in string format.


It returns the number in string format with st, nd, rd, or th added to the end as needed.

Side Effects

The code currently only works with integer size numbers. This should be easy to change though considering the size of code.


Public Function FormatFancyNumber(ByVal sNumber As String) As String
Dim iTemp As Integer
iTemp = Int(sNumber)
If 4 < iTemp And iTemp < 20 Then
  FormatFancyNumber = sNumber & "th"
  Select Case iTemp Mod 10
   Case 1
    FormatFancyNumber = sNumber & "st"
   Case 2
    FormatFancyNumber = sNumber & "nd"
   Case 3
    FormatFancyNumber = sNumber & "rd"
   Case Else
    FormatFancyNumber = sNumber & "th"
  End Select
End If
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 92 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.