本帖最后由 todaynew 于 2010-9-20 13:06 编辑
将日期转换为大写的方法一定很多,可以实现这个功能的函数有Replace、Mid、Choose等。本例死磕Choose函数,主要原因是想摆脱对月和日数字的位数复杂判断,在数组元素较少的情况下,这是一个比较好的方法。
Function Myday(Mydate As Date) As String
'功能:将日期转换为大写
Dim i As Long
Dim n As Long
For i = 1 To 4
n = Val(Mid(Year(Mydate), i, 1))
If n = 0 Then
Myday = Myday & "〇"
Else
Myday = Myday & Choose(n, "一", "二", "三", "四", "五", "六", "七", "八", "九")
End If
Next
Myday = Myday & "年"
n = Month(Mydate)
Myday = Myday & Choose(n, "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二") & "月"
n = Day(Mydate)
Myday = Myday & Choose(n, "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", _
"十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "廿", _
"廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "卅", "卅一") & "日"
End Function
|