这好说,给你一段源程序,
这个函数,我们的软件中打印发票用的。
Function ChangeCase ( GetName , GetCount , SetName , SetName2 )
str =do
cument.GetCaseContent ( GetName , 0 )
Price = CDbl ( str )
str =do
cument.GetCaseContent ( GetCount , 0 )
Count = CLng ( str )
Total = Price * Count
str = CStr ( Total )
do
cument.SetCaseContent ( SetName , str , 0 )
if right ( str , 2 )<> "整" then
Dim money ( 12 )
money ( 1 )= "分"
money ( 2 )= "角"
money ( 3 )= "元"
money ( 4 )= "拾"
money ( 5 )= "百"
money ( 6 )= "千"
money ( 7 )= "万"
money ( 8 )= "拾"
money ( 9 )= "百"
money ( 10 )= "千"
money ( 11 )= "亿"
money ( 12 )= "拾"
max = len ( str )
if max = 4 or max = 3 then
ctemp = left ( str , 1 )
if ctemp = "0" then
ctemp = right ( str , 3 )
str = ctemp
max = max - 1
end if
end if
i = 0
test = clng ( str )
a1 = clng ( test / 1000000000 )
a2 = clng (( test - 1000000000 * a1 )/ 100000000 )
c1 = clng (( test - 1000000000 * a1 - 100000000 * a2 )/ 10000000 )
c2 = clng (( test - 1000000000 * a1 - 100000000 * a2 - 10000000 * c1 )/ 1000000 )
c3 = clng (( test - 1000000000 * a1 - 100000000 * a2 - 10000000 * c1 - 1000000 * c2 )/ 100000 )
c4 = clng (( test - 1000000000 * a1 - 100000000 * a2 - 10000000 * c1 - 1000000 * c2 - 100000 * c3 )/ 10000 )
do
tkey = 0
do
t = right ( str , 1 )
do
t = left (do
t , 1 )
ifdo
t = "." then
do
tkey = 1
end if
whiledo
t <> "." and i <= 3
i = i + 1
do
t = right ( str , i + 1 )
do
t = left (do
t , 1 )
ifdo
t = "." then
do
tkey = 1
end if
wend
if i > 2 then
declen = 0
else
declen = i
end if
newstr = ""
if declen = 0 then
curpos = max + 2 -do
tkey
else
curpos = max
end if
if declen = 2 then
curpos = max - 1
end if
i = 1
store = curpos
key = 1
while i <= max
a = left ( str , i )
a = right ( a , 1 )
select case a
case "1"
newstr = newstr + "壹"
key = 1
case "2"
newstr = newstr + "贰"
key = 1
case "3"
newstr = newstr + "叁"
key = 1
case "4"
newstr = newstr + "肆"
key = 1
case "5"
newstr = newstr + "伍"
key = 1
case "6"
newstr = newstr + "陆"
key = 1
case "7"
newstr = newstr + "柒"
key = 1
case "8"
newstr = newstr + "捌"
key = 1
case "9"
newstr = newstr + "玖"
key = 1
case "0"
a = left ( str , i - 1 )
a = right ( a , 1 )
if a = "0" then
key = 0
end if
if curpos = 7 or curpos = 3 or curpos = 11 then
key = 0
end if
a = left ( str , i + 1 )
a = right ( a , 1 )
if curpos = 8 and a = "0" then
key = 0
end if
m = 1
j = curpos
while j > 2
temp = left ( str , store - j + 1 )
temp = right ( temp , 1 )
if temp = "0" then
m = m + 1
end if
j = j - 1
wend
if m = curpos - j + 1 then
key = 0
end if
if key = 1 then
newstr = newstr + "零"
key = 0
end if
if declen > 0 then
if i = max - declen - 1 then
newstr = newstr + "元"
end if
else
if i = max then
newstr = newstr + "元"
end if
end if
case "."
curpos = curpos + 1
a = left ( str , i + 1 )
a = right ( a , 1 )
b = left ( str , i + 2 )
b = right ( b , 1 )
if a = "0" and b <> "0" then
newstr = newstr + "零"
end if
if declen = 0 then
newstr = newstr + "元"
end if
end select
a = left ( str , i )
a = right ( a , 1 )
if ( a <> "0" and a <> "." ) or ( curpos = 7 and ( c1 <> 0 or c2 <> 0 or c3 <> 0 or c4 <> 0 )) or curpos = 11 then
newstr = newstr + money ( curpos )
if a = "0"and ( curpos = 7 or curpos = 11 ) then
m = 1
j = curpos
while j > 2
temp = left ( str , store - j + 1 )
temp = right ( temp , 1 )
if temp = "0" then
m = m + 1
end if
j = j - 1
wend
if m <> curpos - j + 1 then
newstr = newstr + "零"
key = 0
end if
end if
end if
i = i + 1
curpos = curpos - 1
wend
newstr = newstr + "整"
do
cument.SetCaseContent ( SetName2 , newstr , 0 )
end if
End Function