Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    JustCallMeAl
    Guest

    Cardinal Numbers to Ordinal Numbers

    In the continued pursuit to make our users more efficient and our projects easier to use, I have come upon the need to convert a date using cardinal numbers for the day (i.e., January 26, 1999 or 26 January 1999) to a date using ordinal numbers, i.e., 26th day of January 1999.

    I do not have any questions about the process I am working with except converting from cardinal to ordinal numbers, i.e., 26 to 26th.

    My initial thoughts are to create an array of ordinal numbers, with the array index as the cardinal number. Therefore, producing something like (after, of course, the array has been populated):

    <pre>strDayOfMonth = "26" '(this really gotten from user input)

    strDayOfMonth = strOrdinalDayOfMonth(strDayOfMonth)</pre>


    Does this sound feasible? What are some other alternatives? Is there, Glory Be!, a function already in existence to produce this?

    Thanks for the input.

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Cardinal Numbers to Ordinal Numbers

    Al,

    There's some clever code in <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showthreaded.pl?Cat=&Board=wrd&Number=7243&page=&v iew=&sb=&vc=1#Post7243>this post</A> on the Word forum by Andrew Lockton, that you should be able to adapt.

    In adapting this, the following information from Word help should be helpful:

    <pre>* Ordinal Ordinal arabic text. For example,
    { DATE @ "d" * Ordinal } displays "30th". </pre>

    Gary

  3. #3
    JustCallMeAl
    Guest

    Re: Cardinal Numbers to Ordinal Numbers

    Thanks. One minor change and it works in principle. Thanks.

    BTW, since you mentioned searching Word help, I did just that and still I couldn't find the information about the switch to use in the field code. <img src=/S/frown.gif border=0 alt=frown width=15 height=15>

    Again, thanks.

  4. #4
    JustCallMeAl
    Guest

    Re: Cardinal Numbers to Ordinal Numbers

    I looked in Word 97, and the help information that you quoted is there. However, I couldn't find it in Word2000.

  5. #5
    JustCallMeAl
    Guest

    Re: Cardinal Numbers to Ordinal Numbers

    Is there a "pure" VBA equivalent?

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Cardinal Numbers to Ordinal Numbers

    If there is, it's even better hidden than the Word Help topic on numeric field switches!<g>

    My guess is that the lack of such a function is what prompted the creativity of that workaround.

  7. #7
    JustCallMeAl
    Guest

    Re: Cardinal Numbers to Ordinal Numbers

    Did you see the <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=vb&Number=39302&page=0&view =expanded&sb=5>solution</A> I created?

  8. #8
    Francis Winter
    Guest

    Re: Cardinal Numbers to Ordinal Numbers

    I am probably overlooking the subtle cases, but perhaps you could start with:
    <pre>Function Addth(NumberString As String) As String

    Select Case CLng(Right$(NumberString, 1))
    Case 1
    Addth = NumberString & "st"
    Case 2
    Addth = NumberString & "nd"
    Case 3
    Addth = NumberString & "rd"
    Case Else
    Addth = NumberString & "th"
    End Select

    End Function</pre>


  9. #9
    JustCallMeAl
    Guest

    Re: Cardinal Numbers to Ordinal Numbers

    I like it. Thanks.

  10. #10
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cardinal Numbers to Ordinal Numbers

    The exceptions are 11, 12 and 13.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  11. #11
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Cardinal Numbers to Ordinal Numbers

    Legare, just a little point, VBA (my version anyway) baulks at End Case. I imagine you meant End Select, as used earlier in the code.

    I am a bit confused as there appears to be 2 threads on this topic.

    Andrew

  12. #12
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cardinal Numbers to Ordinal Numbers

    A slight modification to fix a few exceptions:

    <pre>Function Addth(NumberString As String) As String
    Select Case CLng(Right$(NumberString, 1))
    Case 1
    Addth = NumberString & "st"
    Case 2
    Addth = NumberString & "nd"
    Case 3
    Addth = NumberString & "rd"
    Case Else
    Addth = NumberString & "th"
    End Select
    Select Case CLng(Right$(NumberString, 2))
    Case 11, 12, 13
    Addth = NumberString & "th"
    End Select
    End Function
    </pre>

    Legare Coleman

  13. #13
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cardinal Numbers to Ordinal Numbers

    Yes, that is what I meant. I have fixed the post. That's what I get for not testing it first.
    Legare Coleman

  14. #14
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cardinal Numbers to Ordinal Numbers

    fwiw
    <pre>Function Addth(NumberString As String) As String
    Dim strOrdinals As Variant
    strOrdinals = Array("", "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th",_
    "9th", "10th", "11th", "12th", "13th", "14th", "15th", _
    "16th", "17th", "18th", "19th", "20th", "21st", "22nd", _
    "23rd", "24th", "25th", "26th", "27th", "28th", "29th", _
    "30th", "31st")
    Addth = strOrdinals(cint(NumberString))

    End Function
    </pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  15. #15
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cardinal Numbers to Ordinal Numbers

    Wow, forget it.

    Mine takes 12+ times as long as the previous suggestion.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

Page 1 of 2 12 LastLast

Posting Permissions

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