• Welcome to PlanetSquires Forums.
 

Int2Ordinal function

Started by Sean Scott, February 19, 2010, 10:01:27 PM

Previous topic - Next topic

Sean Scott

Here is a function to convert an integer to an ordinal number

Function int2Ordinal(iValue As Integer) As String
   Dim sReturnValue As String
   Dim sLSD As String
   
   sReturnValue = Str$(iValue)
   sLSD = Right$(sReturnValue, 1)
   
   If sLSD = "1" And (iValue < 10 Or iValue > 20) Then
         sReturnValue = sReturnValue & "st"
   ElseIf sLSD = "2" And (iValue < 10 Or iValue > 20) Then
         sReturnValue = sReturnValue & "nd"
   ElseIf sLSD = "3" And (iValue < 10 Or iValue > 20) Then
         sReturnValue = sReturnValue & "rd"
   Else
         sReturnValue = sReturnValue & "th"
   End If
   Function = sReturnValue
End Function