水晶报表金额转大写的vb函数的问题

feng442624978 2009-06-11 10:48:25
我这样有一个 转金额的vb函数:
Function toal (ls as currency) as string
dim dx_sz as string
dim dx_dw as string
dim str_int as string
dim str_dec as string
dim dx_str as string
dim fu as string
dim a as string
dim b as string
dim c as string
dim d as string
dim b2 as string
dim num_int as number
dim num_dec as currency
dim len_int as number
dim i as number
dim a_int as number
dim pp as number

dx_sz="零壹贰叁肆伍陆柒捌玖"
dx_dw="万仟佰拾亿仟佰拾万仟佰拾圆"

if ls<0 then
ls=abs(ls)
fu="负"
else
fu=""
end if

dx_str=CStr (ls)
dx_str=Replace (dx_str,"¥","")
dx_str=replace(dx_str,",","")
if (ls>0) and (ls<1) then dx_str="0"+dx_str

pp=InStr (dx_str,".")
if pp>0 then
str_int=mid(dx_str,1,instr(dx_str,".")-1)
else
str_int=dx_str
end if

num_int=ToNumber (str_int)

if (ls>0) and (ls<1) then
num_dec = ls*100
else
num_dec=(ls-num_int)*100
end if

str_dec=totext(num_dec)
str_dec=replace(str_dec,"¥","")

len_int=len(str_int)
dx_str=""
for i=1 to len_int
a=mid(str_int,i,1)
a_int=tonumber(a)
b=mid(dx_sz,(a_int+1),1)
c=mid(dx_dw,(13-len_int+i),1)
if dx_str<>"" then
d=mid(dx_str,len(dx_str)-1,1)
else
d=""
end if
if(b="零") and ((d="零") or (b=b2) or (c="圆") or (c="万") or (c="亿")) then b=""
if(a="0") and (c<>"圆") and (c<>"万") and (c<>"亿") then c=""
if((c="圆") or (c="万") or (c="亿")) and (d="零") and (a="0") then
dx_str=mid(dx_str,1,len(dx_str)-2)
d=mid(dx_str,len(dx_str)-1,2)
if((c="圆") and (d="万"))or((c="万") and (d="亿")) then c=""
end if
dx_str=dx_str+b+c
b2=b
next i

'处理金额小于1的情况
if len(dx_str)<=2 then dx_str=""
if(num_dec<10)and(ls>0) then
a_int=tonumber(str_dec)
b=mid(dx_sz,(a_int+1),1)
if num_dec=0 then dx_str=dx_str+"整"
if num_dec>0 then dx_str=dx_str+"零"+b+"分"
end if
if num_dec>=10 then
a_int=tonumber(mid(str_dec,1,1))
a=mid(dx_sz,(a_int+1),1)
a_int=tonumber(mid(str_dec,2,1))
b=mid(dx_sz,(a_int+1),1)
if a<>"零" then a=a+"角"
if b<>"零" then b=b+"分" else b=""
dx_str=dx_str+a+b
end if
if ls=0 then dx_str="零圆整"
dx_str=fu+dx_str

dx_str=replace(dx_str,"零亿","亿")
dx_str=replace(dx_str,"零万","万")
dx_str=replace(dx_str,"零千","千")
dx_str=replace(dx_str,"零圆","圆")


toal =dx_str
End Function

-----------------------------------------------------------------------------

但是这个有函数有点问题 ,大于0 小于 10 的时候 就只出现 "整" 字 谁帮我看一下 .....谢谢了.
...全文
146 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿泰 2009-06-12
  • 打赏
  • 举报
回复
你的输入类型是cur,传不进去空吧?

if isnull({字段}) then
'零'
else
toal({字段})
feng442624978 2009-06-12
  • 打赏
  • 举报
回复
还有一个情况. .就是 怎么判断传进去的金额 如果为空 就返回 "零"... 泰哥
阿泰 2009-06-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 feng442624978 的回复:]
但是 显示的时候 如果参数 是 小于10 的整数 它就会只显示 一个 "整" 字...
[/Quote]

实际试过吗?按3楼的方法。

我是实际测试了多种情况的,不是信口说的。
feng442624978 2009-06-12
  • 打赏
  • 举报
回复
但是 显示的时候 如果参数 是 小于10 的整数 它就会只显示 一个 "整" 字...
阿泰 2009-06-11
  • 打赏
  • 举报
回复
'处理金额小于1的情况
if len(dx_str) <=2 then dx_str=""

改为

if len(dx_str) <2 then dx_str=""

暂未发现其他BUG
feng442624978 2009-06-11
  • 打赏
  • 举报
回复
能帮我改一下吗? 我不会弄 ...谢谢了.
wuyq11 2009-06-11
  • 打赏
  • 举报
回复
if num_dec=0 then dx_str=dx_str+"整"
这里判断
参考

4,818

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧