|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『楼 主』:
阿拉伯数字转中文数字VBS版
用笨办法写的,希望各位帮忙测试一下...
(还望高人指点,希望能有更简单的方法,谢谢!)
do
a=0
do until a=1
randomize
sjs=int(rnd*999999999999)
n=inputbox("请输入一个小于1000000000000的整数:","读数",sjs)
if n="" then wscript.quit
if n="0" then exit do
if IsNumeric(n)=false or instr(n,".")<>0 then
msgbox "您输入的不是一个整数,请重新输入!",16+4096,"错误"
elseif left(n,1)=0 then
msgbox "输入错误,您输入的数不能以“0”打头,请重新输入!",16+4096,"错误"
elseif len(n)>12 then
msgbox "您输入的数不能大于“999999999999”,请重新输入!",16+4096,"错误"
else
a=1
end if
loop
y=n
sz=split("0,1,2,3,4,5,6,7,8,9",",")
hz=split("零,一,二,三,四,五,六,七,八,九",",")
for i=0 to 9
n=replace(n,sz(i),hz(i))
next
dw="千百十亿千百十万千百十"
h=len(n)
for i=1 to h
s=s & mid(n,i,1) & mid(dw,12-h+i,1)
next
m=split("零十,零百,零千,零万,零亿",",")
do until instr(s,m(0))=0 and instr(s,m(1))=0 and instr(s,m(2))=0and instr(s,m(3))=0 and instr(s,m(4))=0
s=replace(s,m(0),"零")
s=replace(s,m(1),"零")
s=replace(s,m(2),"零")
s=replace(s,m(3),"万零")
s=replace(s,m(4),"亿零")
loop
s=replace(s,"亿万","亿")
do until instr(s,"零零")=0
s=replace(s,"零零","零")
loop
if len(n)<>1 and right(s,1)="零" then s=left(s,len(s)-1)
if left(s,2)="一十" then s=right(s,len(s)-1)
on error resume next
i=0
do
i=instr(i+1,s,"零")
if mid(s,i+2,1)="千" then s=replace(s,mid(s,i,3),mid(s,i+1,2))
loop until i=0
jx=msgbox ("您输入的数是:" & y & vbcrlf & "读为:" & s & vbcrlf & "是否继续?",vbyesno+32+4096,"系统提示")
if jx=vbno then wscript.quit
s=""
loop [ Last edited by jmz573515 on 2007-3-1 at 10:15 AM ]
|
|
2007-3-1 10:47 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
   『第
2 楼』:
Quote: | Do
a = 0
Do Until a = 1
Randomize
rdnum = Int(Rnd * 999999999999)
n = Inputbox("请输入一个小于1000000000000的整数:", "读数", rdnum)
If n = "" Then wscript.quit
If n = 0 Then Exit Do
If Isnumeric(n) = False Or Instr(n, ".") <> 0 Then
Msgbox "您输入的不是一个整数,请重新输入!", 16 + 4096, "错误"
Elseif Left(n, 1) = 0 Then
Msgbox "输入错误,您输入的数不能以“0”打头,请重新输入!", 16 + 4096, "错误"
Elseif Len(n) > 12 Then
Msgbox "您输入的数不能大于“999999999999”,请重新输入!", 16 + 4096, "错误"
Else
a=1
End If
Loop
Cagain=Msgbox("您输入的数是:" & n & vbCrLf & "读为:" & num2chinese(n) & vbcrlf & "是否继续?",vbyesno+32+4096,"系统提示")
If Cagain=vbNo Then wscript.quit
Loop
Function num2chinese(Num)
Dim numStr,strlen,i
numStr = ReplaceEx(Num, "0;零 ;1;壹 ;2;贰 ;3;叁 ;4;肆 ;5;伍 ;6;陆 ;7;柒 ;8;捌 ;9;玖 ")
strlen = Len(Num)
For i = strlen To 1 Step -1
numStr = Mid(numStr, 1, i * 2 - 1) & Replace(numStr, Mid(numStr, i * 2, 1), Mid("圆拾佰仟万拾佰仟亿拾佰仟万", strlen - i + 1, 1), i * 2, 1)
Next
numStr = ReplaceEx(numStr, "零拾;零;零佰;零;零仟;零;零零零;零;零零;零;零亿;亿;零万;万;零圆;圆;亿万;亿")
num2chinese = numStr
End Function
Function ReplaceEx(Str,reStr)
Dim tmp,Var
ReplaceEx = Str
Var=Split(reStr,";")
For tmp = 0 To (Ubound(Var) - 1) Step 2
ReplaceEx = Replace(ReplaceEx, Var(tmp), Var(tmp + 1))
Next
End Function |
|
希望看了可以提高你的脚本思路和技巧
|
|
2007-3-1 14:03 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『第
3 楼』:
do
a=0
do until a=1
randomize
sjs=int(rnd*999999999999)
n=inputbox("请输入一个小于1000000000000的整数:","读数",sjs)
if n="" then wscript.quit
if n="0" then exit do
if IsNumeric(n)=false or instr(n,".")<>0 then
msgbox "您输入的不是一个整数,请重新输入!",16+4096,"错误"
elseif left(n,1)=0 then
msgbox "输入错误,您输入的数不能以“0”打头,请重新输入!",16+4096,"错误"
elseif len(n)>12 then
msgbox "您输入的数不能大于“999999999999”,请重新输入!",16+4096,"错误"
else
a=1
end if
loop
y=n
sz=split("0,1,2,3,4,5,6,7,8,9",",")
hz=split("零,一,二,三,四,五,六,七,八,九",",")
for i=0 to 9
n=replace(n,sz(i),hz(i))
next
dw="千百十亿千百十万千百十"
h=len(n)
for i=1 to h
s=s & mid(n,i,1) & mid(dw,12-h+i,1)
next
m=split("零十,零,零百,零,零千,零,零零零,零,零零,零,零亿,亿,零万,万,亿万,亿",",")
for i=0 to 14 step 2
s=replace(s,m(i),m(i+1))
next
if len(n)<>1 and right(s,1)="零" then s=left(s,len(s)-1)
if left(s,2)="一十" then s=right(s,len(s)-1)
jx=msgbox ("您输入的数是:" & y & vbcrlf & "读为:" & s & vbcrlf & "是否继续?",vbyesno+32+4096,"系统提示")
if jx=vbno then wscript.quit
s=""
loop [ Last edited by jmz573515 on 2007-7-28 at 10:23 PM ]
|
|
2007-3-1 20:35 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第
4 楼』:
ReplaceEx其实功能和你的这个:
sz=split("0,1,2,3,4,5,6,7,8,9",",")
hz=split("零,一,二,三,四,五,六,七,八,九",",")
for i=0 to 9
n=replace(n,sz(i),hz(i))
next
差不多。。。
只不过是0;零;1;一这样把你的2个数组放在一个数组里(单数和双数保存者)
然后for 而且step 2就是用 双数位的数字替换前面单数为的数字。
主要是因为零十,零,零百,零,零千,零,零零零,零,零零,零,零亿,亿,零万,万,亿万,亿
被替换的和要替换的字符长度不一致……不然不建议用数组(像0123456789转的这个可以直接用mid去取)。
ReplaceEx处理的话,因为用了split函数,所以 被替换和要替换的这个长度不一致就可以解决了。
|
|
2007-3-2 00:38 |
|
|