请问怎样根据界面上的小写数字在打印的时候把它自动转换为大写的数字?有相应的函数吗?

解决方案 »

  1.   

    自己写函数
    Replace()函数怎么样?
      

  2.   

    Function daxie(money As String) As String '
    Dim x As String, y As String
    Const zimu = ".sbqwsbqysbqwsbq" '定义位置代码
    Const letter = "0123456789sbqwy.zjf" '定义汉字缩写
    Const upcase = "零壹贰叁肆伍陆柒捌玖拾佰仟萬億圆整角分" '定义大写汉字
    Dim temp As String
    temp = money
    If InStr(temp, ".") > 0 Then temp = Left(temp, InStr(temp, ".") - 1)If Len(temp) > 16 Then MsgBox "数目太大,无法换算!请输入一亿亿以下的数字", 64, "错误提示": Exit Function '只能转换一亿亿元以下数目的货币!x = Format(money, "0.00") '格式化货币
    y = ""
    For i = 1 To Len(x) - 3
    y = y & Mid(x, i, 1) & Mid(zimu, Len(x) - 2 - i, 1)
    Next
    If Right(x, 3) = ".00" Then
    y = y & "z"          '***元整
    Else
     y = y & Left(Right(x, 2), 1) & "j" & Right(x, 1) & "f"     '*元*角*分
     End If
    y = Replace(y, "0q", "0") '避免零千(如:40200肆萬零千零贰佰)
    y = Replace(y, "0b", "0") '避免零百(如:41000肆萬壹千零佰)
    y = Replace(y, "0s", "0") '避免零十(如:204贰佰零拾零肆)Do While y <> Replace(y, "00", "0")
    y = Replace(y, "00", "0") '避免双零(如:1004壹仟零零肆)
    Loop
    y = Replace(y, "0y", "y") '避免零億(如:210億     贰佰壹十零億)
    y = Replace(y, "0w", "w") '避免零萬(如:210萬     贰佰壹十零萬)
    y = IIf(Len(x) = 5 And Left(y, 1) = "1", Right(y, Len(y) - 1), y) '避免壹十(如:14壹拾肆;10壹拾)
    y = IIf(Len(x) = 4, Replace(y, "0.", ""), Replace(y, "0.", ".")) '避免零元(如:20.00贰拾零圆;0.12零圆壹角贰分)For i = 1 To 19
    y = Replace(y, Mid(letter, i, 1), Mid(upcase, i, 1)) '大写汉字
    Next
    daxie = y
    End Function
      

  3.   

    下面是 xayzmb(行者) ( 修改后的代码:
    Public Function DaXie(txtJE As Double) As String
    On Error GoTo err1
        Dim I As Long   '循环变量
        Dim K As Long   '记录整数位循环位置
        Dim NC As String '输入金额 '
        Dim chrNum As String  '保存从字串中取出的数字
        Dim c1 As String '中文大写单位
        Dim c2 As String '中文角分
        Dim c3 As String '中文大写数字
        Dim Zheng As String  '整数部分
        Dim Xiao As String   '小数部分
        
        NC = Trim(Format(txtJE, "##0.00"))
        c1 = "仟佰拾万仟佰拾亿仟佰拾万仟佰拾元"
        c2 = "角分"
        c3 = "玖捌柒陆伍肆叁贰壹"
        If NC = 0 Then
            DaXie = "零元整"
            Exit Function
        End If
        
        DaXie = ""
        Zheng = Mid(NC, 1, (Len(NC) - 3))
        Xiao = Mid(NC, (Len(Zheng) + 2), 2)
        If Val(Xiao) <> 0 Then
            For I = Len(Xiao) To 1 Step -1
                chrNum = Mid(Xiao, I, 1)
                If chrNum <> 0 Then
                    DaXie = Mid(c2, I, 1) & DaXie
                    DaXie = Mid(c3, (Len(c3) - chrNum + 1), 1) & DaXie
                Else
                    If I = 1 Then
                        DaXie = "零" & DaXie
                    End If
                End If
            Next I
        End If
        
        K = 0
        If Val(Zheng) <> 0 Then
            DaXie = "元" & DaXie
            For I = Len(Zheng) To 1 Step -1
                If (Len(Zheng) - I) = 4 Then
                    If Val(Mid(Zheng, Len(Zheng) - 4, 1)) = 0 And _
                       Mid(DaXie, 1, 1) <> "零" And _
                       Mid(DaXie, 1, 1) <> "元" Then
                        DaXie = "零" & DaXie
                    End If
                    
                    If Len(Zheng) >= 9 Then
                        If Val(Mid(Zheng, Len(Zheng) - 7, 4)) = 0 Then
                            DaXie = DaXie
                        Else
                            DaXie = "万" & DaXie
                        End If
                    Else
                        DaXie = "万" & DaXie
                    End If
                ElseIf (Len(Zheng) - I) = 8 Then
                    If Val(Mid(Zheng, Len(Zheng) - 8, 1)) = 0 And _
                       Mid(DaXie, 1, 1) <> "零" And _
                       Mid(DaXie, 1, 1) <> "元" Then
                        DaXie = "零" & DaXie
                    End If
                    
                    DaXie = "亿" & DaXie
                ElseIf (Len(Zheng) - I) = 12 Then
                    If Val(Mid(Zheng, Len(Zheng) - 12, 1)) = 0 And _
                       Mid(DaXie, 1, 1) <> "零" And _
                       Mid(DaXie, 1, 1) <> "元" Then
                        DaXie = "零" & DaXie
                    End If
                    
                    DaXie = "万" & DaXie
                End If
                chrNum = Mid(Zheng, I, 1)
                If chrNum <> 0 Then
                    If I = Len(Zheng) Then
                        DaXie = Mid(c3, (Len(c3) - chrNum + 1), 1) & DaXie
                    Else
                        If (Len(Zheng) - I) <> 4 And _
                           (Len(Zheng) - I) <> 8 And _
                           (Len(Zheng) - I) <> 12 Then
                            DaXie = Mid(c1, (Len(c1) - K), 1) & DaXie
                        End If
                        DaXie = Mid(c3, (Len(c3) - chrNum + 1), 1) & DaXie
                    End If
                Else
                    If Mid(DaXie, 1, 1) <> "元" And _
                       Mid(DaXie, 1, 1) <> "万" And _
                       Mid(DaXie, 1, 1) <> "亿" Then
                        If Mid(DaXie, 1, 1) <> "零" Then
                            DaXie = "零" & DaXie
                        End If
                    End If
               End If
                K = K + 1
            Next I
        End If
        If Right(Trim(DaXie), 1) <> "分" Then
            DaXie = DaXie & "整"
        End IfExit Function
    err1:
    MsgBox "你输入的数字太长或者格式错误.", , "提示:"
    End Function