1.在代码中写函数
Function DxMnu(ByVal Money As String, Optional ByVal YB As Boolean = True) As String Dim X, Y As String Dim I As Integer Const Zimu = ".sbqwsbqysbqwsbq" ''定义位置代码 Const Letter = "0123456789sbqwy.zjf" ''定义汉字缩写 Const Upcase = "零壹贰叁肆伍陆柒捌玖拾佰仟万亿圆整角分" '定义大写汉字 Dim Temp As String Try Temp = Convert.ToString(Format(Convert.ToDouble(Money), "0.00")) Catch ex As Exception Throw New NotSupportedException("数据给出错误(非数字格式)!") DxMnu = "Error." Exit Function End Try If Len(Temp) > 12 Then Throw New NotSupportedException("数据太大,无法计算(超亿位无法计算)!") DxMnu = "Error." Exit Function End If If InStr(Temp, ".") > 0 Then Temp = Left(Temp, InStr(Temp, ".") - 1) X = Format(Convert.ToDouble(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 If Right(X, 1) = "0" Then Y = Y & Left(Right(X, 2), 1) & "j" & "z" '*元*角*整 Else Y = Y & Left(Right(X, 2), 1) & "j" & Right(X, 1) & "f" ''*元*角*分 End If 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億 贰佰壹十零億) If Val(Mid(Right(Temp, 4), 1, 1)) > 0 Then Y = Replace(Y, "0w", "w0") ''避免无零千(如:102000 拾万贰仟),应该是拾万零贰仟 Else Y = Replace(Y, "0w", "w") ''避免零萬(如:210萬 贰佰壹十零萬) End If '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零圆壹角贰分) If Len(Temp) >= 9 Then '加 Y = Replace(Y, "yw", "y") '避免亿万元 如 100000000,壹亿万元 应该是壹亿元 End If '加 For I = 1 To 19 Y = Replace(Y, Mid(Letter, I, 1), Mid(Upcase, I, 1)) ''大写汉字 Next If YB = False Then Y = Y.Replace("圆整", "") End If DxMnu = Y End Function
2.在文本框中写代码(注意加上code)。
="无税金额合计(大写):" & code.DxMnu(Sum(Fields!bb_sum.Value, "ReportDataSet_BillBody"))