Results 1 to 3 of 3

Thread: How to display the number abbreviations as 1st, 2nd, 3rd [Resolved]

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    105

    How to display the number abbreviations as 1st, 2nd, 3rd [Resolved]

    I'm trying to add the abbreviations to the following numbers 1, 2 ,3 and 4 so that they come out like this 1st, 2nd, 3rd and 4th, ect.
    I'm just using a simple Select Case statement and it works ok, but i was trying to make it more generic for example, how do you deal with any numbers so they display like this in a label or something.

    923rd or 62nd or 101st or 333rd. ect, ect

    It's not very practical to write out ALL the numbers in the Case statement EG: 1, 21, 31, 41...........991, 1001 ect, ect

    Here's the code that i am using, it works ok and i'd proberly only ever want to go up to 200 anyway but that's not the point. It would be better to make it generic so that it displays all the numbers properly. I can't work out how to do it, can anyone help?

    Code:
    'Place the "st", "nd", "rd" and "th" indicators after the numbers
            Dim nPostion As Short
            Dim strPlace As String
    
            nPostion = CInt(Me.txtPostions.Text)
           
            Select Case nPostion
                Case 1, 21, 31, 41, 51, 61, 71, 81, 91, 101
                    strPlace = "st"
                Case 2, 22, 32, 42, 52, 62, 72, 82, 92, 102
                    strPlace = "nd"
                Case 3, 23, 33, 43, 53, 63, 73, 83, 93, 103
                    strPlace = "rd"
                Case Else
                    strPlace = "th"
            End Select
    
    
            'Place the result in the label
            Me.lblPostions.Text = nPostion & strPlace
    Last edited by Wallabie; Aug 3rd, 2003 at 05:13 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width