码迷,mamicode.com
首页 > 数据库 > 详细

Access自定义函数(人民币大写)

时间:2017-01-24 13:44:55      阅读:267      评论:0      收藏:0      [点我收藏+]

标签:highlight   bool   数值   大写   got   else   对不起   pre   exit   

人民币大写函数:整数不超过13位。

Public Function 人民币大写(A) As String
  Dim aa As String
  Dim bb As String
  Dim cc As String
  Dim dd As Byte
  Dim ee As Boolean
  Dim ff As Byte
  Dim i As Integer
  Dim qq As String
    On Error GoTo CH_Err
    If A >= 0 Then
     aa = Int((A + 0.005) * 100)
     Else
     aa = -Int((A + 0.005) * 100)
     End If
      dd = Len(aa)
        For i = dd To 1 Step -1
         qq = Mid(aa, dd - i + 1, 1)
          bb = Mid("零壹贰叁肆伍陆柒捌玖拾", qq + 1, 1)
           If qq <> "0" Then
             If ee = True Then
              cc = cc + "零" + bb + Mid("分角元拾佰仟万拾佰仟亿拾佰仟万拾佰", i, 1)
            Else
              cc = cc + bb + Mid("分角元拾佰仟万拾佰仟亿拾佰仟万拾佰", i, 1)
            End If
              ee = False
            Else
              If i = 1 And qq = "0" Then
                cc = cc + "整"
              If aa = 0 Then
                 cc = ""
              End If
           Exit For
           End If
              If (i Mod 4 = 3) Then
               If ff < 4 Or i = 3 Then
                cc = cc + Mid("分角元拾佰仟万拾佰仟亿拾佰仟", i, 1)
               End If
              End If
            ee = True
         End If
       Next i
       If A >= 0 Then
     CH = cc
     Else
     CH = "负-" & cc
     End If
CH_Exit:
    Exit Function
CH_Err:
If A >= 0 And Len(Int(A)) >= 13 Or A < 0 And Len(Int(A)) >= 14 Then
   
     MsgBox "对不起 !!!" + Chr(13) + "您输入的数值必须是:" & vbNewLine & "整数位不超过 13 位。", vbOKOnly, "警告"
    Else
    MsgBox Error$
    Resume CH_Exit
    End If
 End Function

  

Access自定义函数(人民币大写)

标签:highlight   bool   数值   大写   got   else   对不起   pre   exit   

原文地址:http://www.cnblogs.com/accumulater/p/6346902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!