Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
1st, 2nd, 3rd, 4th, 5th ... nth
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00446283
Message ID:
00446407
Views:
8
Hmmm... given the constraint iNumber can only be 1-31, you could also make it more straightforward:

FUNCTION fOrdinal( iNumber )
return subs("stndrdthththththththththththththththththstndrdthththththththst", (iNumber*2)-1, 2)

>>parameter x
>>return iif(between(x, 11, 13), "th", iif(right(str(X),1) = "1", "st", iif(right(str(X),1) = "2", "nd", iif(right(str(X),1) = "3", "rd", "th"))))
Ken, I spotted your one-liner and felt compelled to match it ;-)
FOR iNumber = 1 TO 31
>   ? "  " + TRANSFORM( iNumber ) + fOrdinal( iNumber )
>NEXT iNumber
>
>****************************
>FUNCTION fOrdinal( iNumber )
>****************************
>   RETURN IIF( NOT BETWEEN( iNumber, 11, 13 ) AND BETWEEN( MOD(iNumber,10), 1, 3 ) ;
>             , SUBSTR( "stndrd", (MOD(iNumber,10) * 2) -1, 2 ) ;
>             , "th" )
kenweber
GCom2 Solutions
Microsoft Certified Professional

Previous
Next
Reply
Map
View

Click here to load this message in the networking platform