|
发表于 2015-1-22 11:01
|
显示全部楼层
本楼为最佳答案
- Function TxtToDigits(Xstr) As Long '汉字转数字
- If InStr(Xstr, "万") > 0 Then
- x = Split(Xstr, "万")
- TxtToDigits = Four_Digits(x(0)) * 10000# + Four_Digits(x(1))
- Else
- TxtToDigits = Four_Digits(Xstr)
- End If
- End Function
- Function Four_Digits(Xstr) As Integer '四位数
- arr = Array("一", "二", "三", "四", "五", "六", "七", "八", "九")
- Set d = CreateObject("scripting.dictionary")
- For i = 0 To UBound(arr)
- d(arr(i)) = i + 1
- Next
- If Xstr Like "十*" Then Xstr = Replace(Xstr, "十", "一十")
- Xstr = Replace(Xstr, "零", "")
- If InStr(Xstr, "千") > 0 Then
- x = Left(Xstr, 1): Four_Digits = d(x) * 1000: Xstr = Replace(Xstr, x & "千", "")
- End If
- If InStr(Xstr, "百") > 0 Then
- x = Left(Xstr, 1): Four_Digits = Four_Digits + d(x) * 100: Xstr = Replace(Xstr, x & "百", "")
- End If
- If InStr(Xstr, "十") > 0 Then
- x = Left(Xstr, 1): Four_Digits = Four_Digits + d(x) * 10: Xstr = Replace(Xstr, x & "十", "")
- End If
- If Len(Xstr) > 0 Then Four_Digits = Four_Digits + d(Left(Xstr, 1))
- End Function
复制代码 |
|