好久没到竞赛区了,今看到守版主的竞赛题:[Word14期]目录提取与自动生成段落 其中关于小写整数数值转换为中文大写,用VBA代码的方法,原以为很简单,想了一下不是太容易。试写一段代码如下: '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Option Explicit Function Num2CNStr(iX As Long) As String '10亿以下的整数转换为中文大写 Dim s1$, s2$, s$, ds$, ts1$, ts2$, k%, i%, iIndex%, StrLen% s1 = "一二三四五六七八九十" s2 = "十百千万十百千亿" s = CStr(iX) ds = "" k = 1 StrLen = Len(s) For i = StrLen To 1 Step -1 iIndex = CInt(Mid(s, i, 1)) If iIndex = 0 Then ts1 = IIf(i = StrLen Or i = StrLen - 4 Or k = 0, "", "零") Else ts1 = Mid(s1, iIndex, 1) End If If i < StrLen Then ts2 = Mid(s2, StrLen - i, 1) ts2 = IIf(i = StrLen Or iIndex = 0 And i <> StrLen - 4, "", ts2) ds = ts1 & ts2 & ds ds = Replace(ds, "亿万", "亿") k = iIndex Next Num2CNStr = ds End Function Sub test() Dim str1$ str1 = Num2CNStr(910000001) MsgBox (str1) End Sub
[此贴子已经被作者于2006-9-4 20:11:37编辑过] |