别人的代码
Option ExplicitPrivate Sub Command1_Click()
Me.Text2.Text = CChinese(Text1.Text)
End Sub'********************************************************************
'说明:把阿拉伯数字转换为汉语
'******************************************************************
Private Function CChinese(StrEng As String) As String
If Not IsNumeric(StrEng) Or StrEng Like "*.*" Or StrEng Like "*-*" Then
If Trim(StrEng) <> "" Then MsgBox "无效的数字"
CChinese = "": Exit Function
End If
Dim intLen As Integer, intCounter As Integer
Dim strCh As String, strTempCh As String
Dim strSeqCh1 As String, strSeqCh2 As String
Dim strEng2Ch As String
strEng2Ch = "零壹贰叁肆伍陆柒捌玖"
strSeqCh1 = " 拾佰仟 拾佰仟 拾佰仟 拾佰仟"
strSeqCh2 = " 万亿兆"
StrEng = CStr(CDec(StrEng))
intLen = Len(StrEng)
For intCounter = 1 To intLen
strTempCh = Mid(strEng2Ch, Val(Mid(StrEng, intCounter, 1)) + 1, 1)
If strTempCh = "零" And intLen <> 1 Then
If Mid(StrEng, intCounter + 1, 1) = "0" Or (intLen - intCounter + 1) Mod 4 = 1 Then
strTempCh = ""
End If
Else
strTempCh = strTempCh & Trim(Mid(strSeqCh1, intLen - intCounter + 1, 1))
End If
If (intLen - intCounter + 1) Mod 4 = 1 Then
strTempCh = strTempCh & Mid(strSeqCh2, (intLen - intCounter + 1) \ 4 + 1, 1)
If intCounter > 3 Then
If Mid(StrEng, intCounter - 3, 4) = "0000" Then strTempCh = Left(strTempCh, Len(strTempCh) - 1)
End If
End If
strCh = strCh & Trim(strTempCh)
Next
CChinese = strCh
End Function
Option ExplicitPrivate Sub Command1_Click()
Me.Text2.Text = CChinese(Text1.Text)
End Sub'********************************************************************
'说明:把阿拉伯数字转换为汉语
'******************************************************************
Private Function CChinese(StrEng As String) As String
If Not IsNumeric(StrEng) Or StrEng Like "*.*" Or StrEng Like "*-*" Then
If Trim(StrEng) <> "" Then MsgBox "无效的数字"
CChinese = "": Exit Function
End If
Dim intLen As Integer, intCounter As Integer
Dim strCh As String, strTempCh As String
Dim strSeqCh1 As String, strSeqCh2 As String
Dim strEng2Ch As String
strEng2Ch = "零壹贰叁肆伍陆柒捌玖"
strSeqCh1 = " 拾佰仟 拾佰仟 拾佰仟 拾佰仟"
strSeqCh2 = " 万亿兆"
StrEng = CStr(CDec(StrEng))
intLen = Len(StrEng)
For intCounter = 1 To intLen
strTempCh = Mid(strEng2Ch, Val(Mid(StrEng, intCounter, 1)) + 1, 1)
If strTempCh = "零" And intLen <> 1 Then
If Mid(StrEng, intCounter + 1, 1) = "0" Or (intLen - intCounter + 1) Mod 4 = 1 Then
strTempCh = ""
End If
Else
strTempCh = strTempCh & Trim(Mid(strSeqCh1, intLen - intCounter + 1, 1))
End If
If (intLen - intCounter + 1) Mod 4 = 1 Then
strTempCh = strTempCh & Mid(strSeqCh2, (intLen - intCounter + 1) \ 4 + 1, 1)
If intCounter > 3 Then
If Mid(StrEng, intCounter - 3, 4) = "0000" Then strTempCh = Left(strTempCh, Len(strTempCh) - 1)
End If
End If
strCh = strCh & Trim(strTempCh)
Next
CChinese = strCh
End Function
Private Function EnToCh(ByVal En As String) As String
Dim Num As Double
Dim I As Long
Dim L As Long
Dim M As Long
Dim N As Long
Dim Tmp As Double
Dim CNum(23) As String
Dim TmpNum() As String
Dim TmpNum1() As String
Dim TmpStr As String
En = Trim(En)
If Not IsNumeric(En) Then
EnToCh = "Êý×ÖÊäÈë´íÎó"
Exit Function
End IfCNum(0) = "铃"
CNum(1) = "医"
CNum(2) = "尔"
CNum(3) = "伞"
CNum(4) = "斯"
CNum(5) = "舞"
CNum(6) = "瘤"
CNum(7) = "奇"
CNum(8) = "霸"
CNum(9) = "酒"
CNum(10) = ""
CNum(11) = "屎"
CNum(12) = "摆"
CNum(13) = "牵"
CNum(14) = "园"
CNum(15) = "碗"
CNum(16) = "议"
CNum(17) = "照"
CNum(18) = "精"
CNum(19) = "粉"
CNum(20) = "脚"
CNum(21) = "陵"
CNum(22) = "蒸"
CNum(23) = "妇"
En = Trim(En)
En = Replace(En, ",", "")
TmpNum1 = Split(En, ".")
If UBound(TmpNum1) > 1 Then
EnToCh = 错误数字,多于一个小数点"
Exit Function
End IfI = Len(TmpNum1(0))
If Left(TmpNum1(0), 1) = "-" Then
TmpNum1(0) = Right(TmpNum1(0), I - 1)
En = CNum(23)
I = I - 1
Else
En = ""
End If
If I > 20 Then
EnToCh = "数字太长,无法计算"
Exit Function
End IfM = I
L = ((I - 1) \ 4)
ReDim TmpNum(L)
TmpStr = TmpNum1(0)
For N = 0 To L
TmpNum(N) = Right(TmpStr, 4)
M = M - 4
If M > 0 Then TmpStr = Left(TmpNum1(0), M)
NextFor I = L To 0 Step -1
Tmp = Val(TmpNum(I))
For M = 3 To 0 Step -1
N = (Tmp \ (10 ^ M)) Mod 10
EnToCh = EnToCh & CNum(N) & CNum(M + 10)
Next
EnToCh = EnToCh & CNum(I + 14)
NextFor L = 11 To 13
EnToCh = Replace(EnToCh, CNum(0) & CNum(L), CNum(0))
EnToCh = Replace(EnToCh, CNum(0) & CNum(0), CNum(0))
Next
For N = 0 To 2
For L = 15 To 18
EnToCh = Replace(EnToCh, CNum(0) & CNum(L), CNum(L))
Next
For I = 18 To 16 Step -1
For L = I - 1 To 15 Step -1
EnToCh = Replace(EnToCh, CNum(I) & CNum(L), CNum(I) & CNum(0))
Next
Next
EnToCh = Replace(EnToCh, CNum(0) & CNum(0), CNum(0))
NextIf Left(EnToCh, 1) = CNum(0) Then EnToCh = Right(EnToCh, Len(EnToCh) - 1)
EnToCh = Replace(EnToCh, CNum(0) & CNum(14), CNum(14)) If UBound(TmpNum1) > 0 Then
TmpStr = Left(TmpNum1(1) & "0", 2)
Tmp = Val(TmpStr)
If Tmp = 0 Then
EnToCh = EnToCh & CNum(22)
Else
For M = 1 To 0 Step -1
N = (Tmp \ (10 ^ M)) Mod 10
EnToCh = EnToCh & CNum(N) & CNum(M + 19)
Next
End If
Else
EnToCh = EnToCh & CNum(22)
End If
EnToCh = Replace(EnToCh, CNum(0) & CNum(19), "")
EnToCh = Replace(EnToCh, CNum(0) & CNum(20), CNum(0)) EnToCh = En & EnToCh
End Function使用方法:
SUB COMMAND1_CLICK()
MSGBOX EntoCh("19234723298432497.92")
end sub