1. 程式人生 > >VB阿拉伯數字金額轉大寫中文

VB阿拉伯數字金額轉大寫中文

Function mychange(ByVal Myinput)
    Dim Temp, TempA, MyinputA, MyinputB, MyinputC
    Dim Place As String
    Dim J As Integer
    Place = "分角元拾佰仟萬拾佰仟億拾佰仟萬"
    shuzi1 = "壹貳叄肆伍陸柒捌玖"
    shuzi2 = "整零元零零零萬零零零億零零零萬"
    
    qianzhui = ""
    If Val(Myinput) = 0 Then Myinput = 0
    If Myinput = "" Then Myinput = 0
    If Myinput < 0 Then qianzhui = "負"
    Myinput = Int(Abs(Myinput) * 100 + 0.5)
    If Myinput > 999999999999999# Then
      mychange = "數字太大了吧???"
      Exit Function
    End If
    If Myinput = 0 Then
      mychange = "零元零分"
      Exit Function
    End If
    
    MyinputA = Trim(Str(Myinput))
    shuzilong = Len(MyinputA)
    For J = 1 To shuzilong
    MyinputB = Mid(MyinputA, J, 1) & MyinputB
    Next
    For J = 1 To shuzilong
      Temp = Val(Mid(MyinputB, J, 1))
      If Temp = 0 Then
         MyinputC = Mid(shuzi2, J, 1) & MyinputC
      Else
         MyinputC = Mid(shuzi1, Temp, 1) & Mid(Place, J, 1) & MyinputC
      End If
    Next
    
    shuzilong = Len(MyinputC)
    For J = 1 To shuzilong - 1
      If Mid(MyinputC, J, 1) = "零" Then
         Select Case Mid(MyinputC, J + 1, 1)
            Case "零", "元", "萬", "億", "整":
            MyinputC = Left(MyinputC, J - 1) & Mid(MyinputC, J + 1, 30)
            J = J - 1
         End Select
      End If
    Next
    
    shuzilong = Len(MyinputC)
    For J = 1 To shuzilong - 1
       If Mid(MyinputC, J, 1) = "億" And Mid(MyinputC, J + 1, 1) = "萬" Then
         MyinputC = Left(MyinputC, J) & Mid(MyinputC, J + 2, 30)
         Exit For
       End If
    Next
    
    mychange = qianzhui & Trim(MyinputC)
    
End Function