'調用方法Text2=ChMoney(Val(Text1))
'名稱:CCh
'得到一位數字N1的漢字大寫
'0返回""
PrivateFunctionCCh(N1)AsString
SelectCaseN1
Case0
CCh="零"
Case1
CCh="壹"
Case2
CCh="貳"
Case3
CCh="三"
Case4
CCh="肆"
Case5
CCh="伍"
Case6
CCh="陸"
Case7
CCh="柒"
Case8
CCh="捌"
Case9
CCh="玖"
EndSelect
EndFunction
'名稱:ChMoney
'得到數字N1的漢字大寫
'最大為千萬位
'O返回""
PublicFunctionChMoney(N1)AsString
DimtMoneyAsString
DimlMoneyAsString
Dimtn'小數位置
Dims1AsString'臨時STRING小數部分
Dims2AsString'1000以內
Dims3AsString'10000
IfN1=0Then
ChMoney=""
ExitFunction
EndIf
IfN1<0Then
ChMoney="負" ChMoney(Abs(N1))
ExitFunction
EndIf
tMoney=Trim(Str(N1))
tn=InStr(tMoney,".")'小數位置
s1=""
Iftn<>0Then
ST1=Right(tMoney,Len(tMoney)-tn)
IfST1<>""Then
t1=Left(ST1,1)
ST1=Right(ST1,Len(ST1)-1)
Ift1<>"0"Then
s1=s1 CCh(Val(t1)) "角"
EndIf
IfST1<>""Then
t1=Left(ST1,1)
s1=s1 CCh(Val(t1)) "分"
EndIf
EndIf
ST1=Left(tMoney,tn-1)
Else
ST1=tMoney
EndIf
s2=""
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
s2=CCh(Val(t1)) s2
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "拾" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "佰" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "仟" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
s3=""
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
s3=CCh(Val(t1)) s3
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "拾" s3
Else
IfLeft(s3,1)<>"零"Thens3="零" s3
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "佰" s3
Else
IfLeft(s3,1)<>"零"Thens3="零" s3
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "仟" s3
EndIf
EndIf
IfRight(s2,1)="零"Thens2=Left(s2,Len(s2)-1)
IfLen(s3)>0Then
IfRight(s3,1)="零"Thens3=Left(s3,Len(s3)-1)
s3=s3&"萬"
EndIf
ChMoney=IIf(s3&s2="",s1,s3&s2&"元"&s1)
EndFunction
'調用方法Text2=ChMoney(Val(Text1))
'名稱:CCh
'得到一位數字N1的漢字大寫
'0返回""
PrivateFunctionCCh(N1)AsString
SelectCaseN1
Case0
CCh="零"
Case1
CCh="壹"
Case2
CCh="貳"
Case3
CCh="三"
Case4
CCh="肆"
Case5
CCh="伍"
Case6
CCh="陸"
Case7
CCh="柒"
Case8
CCh="捌"
Case9
CCh="玖"
EndSelect
EndFunction
'名稱:ChMoney
'得到數字N1的漢字大寫
'最大為千萬位
'O返回""
PublicFunctionChMoney(N1)AsString
DimtMoneyAsString
DimlMoneyAsString
Dimtn'小數位置
Dims1AsString'臨時STRING小數部分
Dims2AsString'1000以內
Dims3AsString'10000
IfN1=0Then
ChMoney=""
ExitFunction
EndIf
IfN1<0Then
ChMoney="負" ChMoney(Abs(N1))
ExitFunction
EndIf
tMoney=Trim(Str(N1))
tn=InStr(tMoney,".")'小數位置
s1=""
Iftn<>0Then
ST1=Right(tMoney,Len(tMoney)-tn)
IfST1<>""Then
t1=Left(ST1,1)
ST1=Right(ST1,Len(ST1)-1)
Ift1<>"0"Then
s1=s1 CCh(Val(t1)) "角"
EndIf
IfST1<>""Then
t1=Left(ST1,1)
s1=s1 CCh(Val(t1)) "分"
EndIf
EndIf
ST1=Left(tMoney,tn-1)
Else
ST1=tMoney
EndIf
s2=""
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
s2=CCh(Val(t1)) s2
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "拾" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "佰" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s2=CCh(Val(t1)) "仟" s2
Else
IfLeft(s2,1)<>"零"Thens2="零" s2
EndIf
EndIf
s3=""
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
s3=CCh(Val(t1)) s3
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "拾" s3
Else
IfLeft(s3,1)<>"零"Thens3="零" s3
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "佰" s3
Else
IfLeft(s3,1)<>"零"Thens3="零" s3
EndIf
EndIf
IfST1<>""Then
t1=Right(ST1,1)
ST1=Left(ST1,Len(ST1)-1)
Ift1<>"0"Then
s3=CCh(Val(t1)) "仟" s3
EndIf
EndIf
IfRight(s2,1)="零"Thens2=Left(s2,Len(s2)-1)
IfLen(s3)>0Then
IfRight(s3,1)="零"Thens3=Left(s3,Len(s3)-1)
s3=s3&"萬"
EndIf
ChMoney=IIf(s3&s2="",s1,s3&s2&"元"&s1)
EndFunction->