I want to make a date on a report look like a real date, that is, in England
we say Tuesday 26th October 2004.
Using the Format function, I can say Tuesday 26 October 2004 thus:
Label2 = "Survey Closing : " & Format((dDate), "dddd dd MMMM YYYY")
I want to indicate the number's, (date), ordinal value, ie st, rd, th,nd.
Is there a way to do this, my books are not really too forthcoming.
Thank you for your time.
Best regards.
David Clifford
Here's a sample that does some of this...
Implementing a Number-To-Text Conversion Function
http://vbnet.mvps.org/index.html?code/helpers/numbertofraction.htm
It outputs the entire word. It shouldn't take too long to convert that
into something the just adds the suffix.
--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
Thanks for your time.
Best regards.
David Clifford
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:eYRjyk4u...@TK2MSFTNGP10.phx.gbl...
> Hello all.
>
> I want to make a date on a report look like a real date, that is, in England
> we say Tuesday 26th October 2004.
>
> Using the Format function, I can say Tuesday 26 October 2004 thus:
>
> Label2 = "Survey Closing : " & Format((dDate), "dddd dd MMMM YYYY")
>
> I want to indicate the number's, (date), ordinal value, ie st, rd, th,nd.
> Is there a way to do this, my books are not really too forthcoming.
Perhaps you can use (and/or learn from) this simple thing:
Option Explicit
Public Function numeric_suffix(sIn As String) As String
Select Case Val(Right$(RTrim$(sIn), 2))
Case 0, 4 To 20
numeric_suffix = "th"
Exit Function
End Select
Select Case Val(Right$(RTrim$(sIn), 1))
Case 0, 4 To 9
numeric_suffix = "th"
Case 1
numeric_suffix = "st"
Case 2
numeric_suffix = "nd"
Case 3
numeric_suffix = "rd"
End Select
End Function
Public Function suffixize(sIn As String, Optional begin As Integer = 1) As String
'find first digit-followed-by-space, insert suffix
Dim i As Long, ch As String
i = begin
Do While i
i = InStr(i + 1, sIn, " ")
If i > 1 Then
ch = Mid$(sIn, i - 1, 1)
If 0 < InStr(1, "0123456789", ch) Then
suffixize = Mid$(sIn, 1, i - 1) & _
numeric_suffix(Mid$(sIn, i - 2, 2)) _
& Mid$(sIn, i)
Exit Function
End If
End If
Loop
'none found with following space, use last characters
ch = Right$(sIn, 2)
suffixize = sIn & numeric_suffix(ch)
End Function
Seemed like an interesting puzzle at first, but only took me
5-10 minutes to get that far. I'm not overly happy with "0th"
but that shouldn't come up in a calendar anyway.
Bob
Come on... all that is required is a simple one-line function.<g>
Function Oneliner(Number As Long) As String
Oneliner = IIf(Partition(Number Mod 100, 1, 13, 5) <> "11:13" And _
Partition(Number Mod 10, 1, 9, 3) = " 1: 3", _
Choose(Number Mod 10, "st", "nd", "rd"), "th")
End Function
I've used Choose before, but I'll bet that Partition function is a new
one on you, right?
Rick - MVP
Actually, 0th is fine. Look up zeroth in the dictionary.
Rick - MVP
New to me <g> fwiw, I've never used Choose either. Those methods are
obviously there to support "one liner" fans eh? ;-)
Actually, I have a "religious" aversion to IIF, which dates back to when it
was an *external* library function. I've heard that it isn't any more, but
I still won't use it.
Partition I was vaguely aware of, but only in database calls.
Just as a guess, I'd estimate your version takes one or two (binary) orders of
magnitude more cycles, and requires a numeric input to boot. One-liners make
interesting puzzles sometimes, but only in the very rare cases where they
actually enhance readability would I even consider using one - outside of
an academic context like this thread.
Bob
They both existed in VB3 for sure (I don't know about earlier versions).
> Those methods are obviously there to support "one liner" fans eh? ;-)
I wouldn't know, I'm not aware of any "one liner" fans in this
newsgroups.<g>
Rick - MVP
Your response seems way too serious for a reply to a post that included
a <g> in it.<g>
You are right, though, the code I posted would not be a speed demon by
any means. And I don't use IIf (or Choose, or Switch, or Partition,
etc.) in any of my serious coding either. The only reason I posted the
one-liner is because it has been awhile since I have done so and I
figured my "fans" were due one.<g>
Rick - MVP
> any means. And I don't use IIf (or Choose, or Switch, or Partition,
> etc.) in any of my serious coding either. The only reason I posted the
I don't either, but it does help me sometimes when trying to use the debug
window to its full extent.
> one-liner is because it has been awhile since I have done so and I
> figured my "fans" were due one.<g>
And this one appreciates that fact! <g>
Matt