SoFunction
Updated on 2025-04-13

Fun VBS special code page 2/6



VBS' string operation is also very convenient. The following is a comparison of the two scripts converting RMB into Chinese characters
<SCRIPT LANGUAGE=vbs>
N=34334100000.0502'Suppose N is not a negative number, and there is no 0 at the end
Snz=split(cstr(N),".")(0)'Integer part to string
A=array( "zero","one","two","three","si","wu","lu","seven","ba","nine")
B=array("yuan","se","bai","qian","xin","shift","lift","qian","qian","qian","qian","qian","qian","xin","lind")
C=array("angle","min","li","max")
WeiSz=len(cstr(int(Snz)))' integer digits
for i=1 to WeiSz       
              JieG=JieG & A(cint(mid(Snz,i,1)))        
              if cint(mid(Snz,i,1))<>0 or _
              (WeiSz-i)=0 or (WeiSz-i)=4 or _
              (WeiSz-i)=8 or (WeiSz-i)=12  then JieG=JieG & B(WeiSz-i) 
JieG=replace(JieG,"zero zero","")
next
JieG=replace(JieG,"zero","")
if N<>int(N) then 
JieG=JieG &"zero"
Snx=split(cstr(N),".")(1)'The decimal part turns string
WeiSx=len(cstr(int(Snx)))' Decimal places
       for i=1 to WeiSx       
              if cint(mid(Snx,i,1))=0 then i=i+1              
              JieG=JieG & A(cint(mid(Snx,i,1))) & C(i-1) 
       next
end if
msgbox JieG
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
function Chinese(num) //Translation of Arabic numerals into Chinese capital numerals
{
    if(!num)
{alert("Number is wrong!"); return "Number is wrong!";}
var AA = new Array("zero","one","two","three","si","wu","lu","seven","ba","nine");
var BB = new Array("","select","billion","sen","million","dou","dou","");

    var a = (""+ num).replace(/(^0*)/g, "").split("."), k = 0, re = "";
    for(var i=a[0].length-1; i>=0; i--)
    {
        switch(k)
        {
            case 0 : re = BB[7] + re; break;
            case 4 : if(!new RegExp("0{4}\{"+ (a[0].length-i-1) +"}$").test(a[0]))
                     re = BB[4] + re; break;
            case 8 : re = BB[5] + re; BB[7] = BB[5]; k = 0; break;
        }
        if(k%4 == 2 && a[0].charAt(i+2) != 0 && a[0].charAt(i+1) == 0) re = AA[0] + re;
        if(a[0].charAt(i) != 0) re = AA[a[0].charAt(i)] + BB[k%4] + re; k++;
    }
if(>1) //Add the decimal part (if there is a decimal part)
    {
        re += BB[6];
        for(var i=0; i<a[1].length; i++) re += AA[a[1].charAt(i)];
    }
    return re;
}
alert(Chinese("34334100000.0502"));
</script>

There is another technique to convert numbers into Chinese characters, let’s try it out:
<SCRIPT LANGUAGE=vbs>
for i=1 to 10
   alert left(MonthName(i,True),1)
next
</SCRIPT>

It is date to Chinese characters:

<SCRIPT LANGUAGE=vbs>

Function D(x)
 if int(split(x,"-")(2)/10)=0 then D=D & F(split(x,"-")(2)) else _
if split(x,"-")(2) mod 10 =0 then D=D & F(int(split(x,"-")(2)/10)) & "Ten" else _
D=D & F(int(split(x,"-")(2)/10)) & "Ten" & F(split(x,"-")(2) mod 10)
D=F(split(x,"-")(0)) & "Year" & MonthName(split(x,"-")(1),True) & replace(D,"10","Ten") & "Day"
end Function

Function F(x)
 for i=1 to len(x)
if mid(x,i,1)="0" then F=F & "zero" else F=F & left(MonthName(mid(x,i,1),True),1)
 next
end Function

msgbox D(date)

</SCRIPT>
Previous page123456Next pageRead the full text