# Thread: Cardinal Numbers to Ordinal Numbers

1. ## 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. ## 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. ## 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. ## 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. ## Re: Cardinal Numbers to Ordinal Numbers

Is there a "pure" VBA equivalent?

6. ## 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. ## 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. ## 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
Case 2
Case 3
Case Else
End Select

End Function</pre>

9. ## Re: Cardinal Numbers to Ordinal Numbers

I like it. Thanks.

10. ## Re: Cardinal Numbers to Ordinal Numbers

The exceptions are 11, 12 and 13.

11. ## 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. ## 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
Case 2
Case 3
Case Else
End Select
Select Case CLng(Right\$(NumberString, 2))
Case 11, 12, 13
End Select
End Function
</pre>

13. ## 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.

14. ## 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")

End Function
</pre>

15. ## Re: Cardinal Numbers to Ordinal Numbers

Wow, forget it.

Mine takes 12+ times as long as the previous suggestion.

Page 1 of 2 12 Last

#### Posting Permissions

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