|
-
Jul 4th, 2005, 01:08 AM
#1
Thread Starter
Frenzied Member
Easy Function to add a suffix to a number ie, 1st, 2nd, 3rd, etc..
Hey, this isn't rocket science, but it took me a good twenty minutes of thought.. I think this should cover all positive integers from 0-infinity.
VB Code:
Private Function addsuffix(ByVal num As Integer) As String
Dim suff As String
If num < 0 Then Return "Error"
If num < 20 Then
Select Case num
Case 1 : suff = "st"
Case 2 : suff = "nd"
Case 3 : suff = "rd"
Case 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 : suff = "th"
End Select
Else
Select Case Convert.ToString(num).Chars(Convert.ToString(num).Length - 1)
Case "1" : suff = "st"
Case "2" : suff = "nd"
Case "3" : suff = "rd"
Case Else : suff = "th"
End Select
End If
AddSuffix = Convert.ToString(num) + suff
End Function
Bill
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|