以下是一段用VBA代码编写的金额小写转大写的函数:
public function zdx(x as currency) as string
dim lnp as integer
dim prc as string
dim tmp as string
dim nob as currency
dim dx as string
dim xx as string
dim zhen as boolean
dim str(10) as string
dim china as string
china = "分角元拾佰仟万拾佰仟亿"
str(0) = "零"
str(1) = "壹"
str(2) = "贰"
str(3) = "叁"
str(4) = "肆"
str(5) = "伍"
str(6) = "陆"
str(7) = "柒"
str(8) = "捌"
str(9) = "玖"
zhen = true
x = formatnumber(x, 2)
prc = cstr(x)
prc = replace(prc, ",", "")
lnp = len(prc)
for i = lnp - 1 to 1 step -1
if mid(prc, i, 1) = "." then
select case lnp - i
case 1
prc = replace(prc, ".", "") + "0"
case 2
prc = replace(prc, ".", "")
end select
zhen = false
exit for
end if
next i
if zhen then prc = prc + "00"
lnp = len(prc)
for i = 1 to lnp
tmp = str(mid(prc, i, 1)) & tmp
next i
zdx = ""
fy = 1
for i = 1 to lnp
xx = mid(tmp, i, 1)
dx = mid(china, i, 1)
if xx <> "零" then
zdx = xx & dx & zdx
f = 1
else
if i = 3 then
zdx = dx & zdx
end if
if i = 7 then
zdx = dx & zdx
end if
if f then
zdx = "零" & zdx
end if
f = 0
end if
next i
if zhen then zdx = zdx + "正"
zdx = replace(zdx, "零万", "万")
zdx = replace(zdx, "零元", "元")
end function