怎么在vb中定义一个数组,在文本框中随机生成中文数字大写金额?

这段代码写在哪里?... 这段代码写在哪里? 展开
 我来答
wu_xiaolin2009
2010-08-13 · TA获得超过632个赞
知道小有建树答主
回答量:378
采纳率:0%
帮助的人:296万
展开全部
'定义数组:
dim chap(21, 1)
'初始化:

chap(0, 0) = "万": chap(0, 1) = 10000
chap(1, 0) = "仟": chap(1, 1) = 1000
chap(2, 0) = "佰": chap(2, 1) = 100
chap(3, 0) = "拾": chap(3, 1) = 10
chap(4, 0) = "元": chap(4, 1) = 1
chap(5, 0) = "角": chap(5, 1) = 0.1
chap(6, 0) = "分": chap(6, 1) = 0.01
chap(11, 0) = "壹": chap(11, 1) = 1
chap(12, 0) = "贰": chap(12, 1) = 2
chap(13, 0) = "叁": chap(13, 1) = 3
chap(14, 0) = "肆": chap(14, 1) = 4
chap(15, 0) = "伍": chap(15, 1) = 5
chap(16, 0) = "陆": chap(16, 1) = 6
chap(17, 0) = "柒": chap(17, 1) = 7
chap(18, 0) = "捌": chap(18, 1) = 8
chap(19, 0) = "玖": chap(19, 1) = 9
chap(20, 0) = "零": chap(20, 1) = 0
chap(21, 0) = "亿": chap(21, 1) = 100000000

function subtochinese(price as integer)
转化千百十
dim i as integer
dim num(15) as integer
i = 1
do until price = 0
num(i) = int(price / chap(i, 1))
if num(i) <> 0 then
subtochinese = subtochinese & chap(num(i) + 10, 0) & chap(i, 0)
price = price - num(i) * chap(i, 1)
else
if subtochinese <> "" and right(subtochinese, 1) <> "零" then
subtochinese = subtochinese & "零"
end if
end if
i = i + 1
loop
if right(subtochinese, 1) = "元" then
subtochinese = left(subtochinese, len(subtochinese) - 1)
end if
end function

function pricetochinese(price as double)
if price >= 100000000 then 大于1亿
pricetochinese = pricetochinese & pricetochinese(int(price / 100000000)) & "亿"
price = price - int(price / 100000000) * 100000000
end if
if price >= 10000 then
pricetochinese = pricetochinese & subtochinese(int(price / 10000)) & "万"
price = price - int(price / 10000) * 10000
end if
if int(price) <> 0 then 如果万与千间无数,则应添零
if pricetochinese <> "" and int(price) < 1000 then
pricetochinese = pricetochinese & "零"
end if
pricetochinese = pricetochinese & subtochinese(int(price))
price = price - int(price)
end if
if pricetochinese <> "" then pricetochinese = pricetochinese & "元"
if price = 0 then 到元为止
pricetochinese = pricetochinese & "整"
else
price = int(price * 100)
if int(price / 10) <> 0 then
pricetochinese = pricetochinese & chap(int(price / 10) + 10, 0) & "角"
price = price - int(price / 10) * 10
end if
if price <> 0 then
pricetochinese = pricetochinese & chap(int(price) + 10, 0) & "分"

end if
end if
end function
帐号已注销
2010-08-13 · TA获得超过1808个赞
知道大有可为答主
回答量:1971
采纳率:0%
帮助的人:2325万
展开全部
'本代码输出格式为类似发票上的金额填写格式,非读法格式.
Private Sub Form_Click()
Randomize
b = Array("分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿")
s = Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖")
m = 100000000 '最大金额
x = Format(Int(Rnd * m * 100) / 100, "0.00")
Text1.Text = x & "元"
y = CStr(x * 100) '从最高非零位处理
'y = CStr(Format(x * 100, "00000000000")) '从亿位开始处理
dx = ""
For i = Len(y) To 1 Step -1
dx = Mid(y, i, 1) & b(Len(y) - i) & dx
Next i
For i = 0 To 9
dx = Replace(dx, i, s(i))
Next i
dx = Replace(dx, "零角零分", "整")

Text2.Text = dx
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式