Private Sub Command1_Click() Dim str1 As String Dim str2 As String str1 = "一二三四五六七八九" str2 = "壹贰叁肆伍陆柒捌玖" Dim i As Long, temp As String Dim strtemp As String, index As Long strtemp = "" If Len(Text1.Text) = 0 Then Exit Sub For i = 1 To Len(Text1.Text) temp = Mid(Text1.Text, i, 1) index = InStr(1, str1, temp) If index > 0 Then temp = Mid(str2, index, 1) End If strtemp = strtemp + temp Next Text2.Text = strtemp End Sub 大致就这样
Public Function ZDX(X As Currency) As String Dim lnP As Integer Dim Prc As String Dim Tmp As String Dim NoB As Currency Dim Dx As String Dim Xx As String Dim Zhen As Boolean Dim Str(10) As String Dim China As String China = "分角元拾佰仟万拾佰仟亿" Str(0) = "零" Str(1) = "壹" Str(2) = "贰" Str(3) = "叁" Str(4) = "肆" Str(5) = "伍" Str(6) = "陆" Str(7) = "柒" Str(8) = "捌" Str(9) = "玖"Zhen = True X = FormatNumber(X, 2) Prc = CStr(X) Prc = Replace(Prc, ",", "")lnP = Len(Prc) For i = lnP - 1 To 1 Step -1 If Mid(Prc, i, 1) = "." Then Select Case lnP - i Case 1 Prc = Replace(Prc, ".", "") + "0" Case 2 Prc = Replace(Prc, ".", "") End Select Zhen = False Exit For End If Next i If Zhen Then Prc = Prc + "00" lnP = Len(Prc) For i = 1 To lnP Tmp = Str(Mid(Prc, i, 1)) & Tmp Next iZDX = "" fy = 1 For i = 1 To lnP Xx = Mid(Tmp, i, 1) Dx = Mid(China, i, 1)If Xx <> "零" Then ZDX = Xx & Dx & ZDX f = 1 Else If i = 3 Then ZDX = Dx & ZDX End IfIf i = 7 Then ZDX = Dx & ZDX End If If f Then ZDX = "零" & ZDX End If f = 0 End If Next i If Zhen Then ZDX = ZDX + "正" ZDX = Replace(ZDX, "零万", "万") ZDX = Replace(ZDX, "零元", "元")End Function
给一个例子。Public Function Int2Chn(ByVal L_num As Long) As String Dim n_data, num, c_data, n_str As String Dim i, j, k, l As Long num = L_num n_data = String(14 - Len(Trim(CStr(Abs(num * 100)))), " ") + Trim(CStr(Abs(num) * 100)) For i = 1 To 14 Step 1 n_str = Mid(n_data, i, 1) If n_str <> " " Then If Mid(n_data, i, 2) = "00" Or (n_str = "0" And (i = 4 Or i = 8 Or i = 12 Or i = 14)) Then Else c_data = c_data + Trim(Mid("零壹贰叁肆伍陆柒捌玖", CInt(n_str) + 1, 1)) End If If n_str = "0" And i <> 4 And i <> 8 And i <> 12 Then Else c_data = c_data + Trim(Mid("仟佰拾亿仟佰拾万仟佰拾圆角分", i, 1)) End If If Right(c_data, 4) = "亿万" Then c_data = Left(c_data, Len(c_data) - 1) End If Next If num < 0 Then c_data = "(负数)" + c_data If num = 0 Then c_data = "零圆" If n_str = "0" Then c_data = c_data + "整" Int2Chn = c_data End Function
to bydisplay(时光) 我要的两个文本框和一个按钮在哪里?再细一点,谢谢你!!!
Private Sub Command1_Click() Text2 = ZDX(Val(Text1.Text)) End Sub
Dim str1 As String
Dim str2 As String
str1 = "一二三四五六七八九"
str2 = "壹贰叁肆伍陆柒捌玖"
Dim i As Long, temp As String
Dim strtemp As String, index As Long
strtemp = ""
If Len(Text1.Text) = 0 Then Exit Sub
For i = 1 To Len(Text1.Text)
temp = Mid(Text1.Text, i, 1)
index = InStr(1, str1, temp)
If index > 0 Then
temp = Mid(str2, index, 1)
End If
strtemp = strtemp + temp
Next
Text2.Text = strtemp
End Sub
大致就这样
Dim lnP As Integer
Dim Prc As String
Dim Tmp As String
Dim NoB As Currency
Dim Dx As String
Dim Xx As String
Dim Zhen As Boolean
Dim Str(10) As String
Dim China As String
China = "分角元拾佰仟万拾佰仟亿"
Str(0) = "零"
Str(1) = "壹"
Str(2) = "贰"
Str(3) = "叁"
Str(4) = "肆"
Str(5) = "伍"
Str(6) = "陆"
Str(7) = "柒"
Str(8) = "捌"
Str(9) = "玖"Zhen = True
X = FormatNumber(X, 2)
Prc = CStr(X)
Prc = Replace(Prc, ",", "")lnP = Len(Prc)
For i = lnP - 1 To 1 Step -1
If Mid(Prc, i, 1) = "." Then
Select Case lnP - i
Case 1
Prc = Replace(Prc, ".", "") + "0"
Case 2
Prc = Replace(Prc, ".", "")
End Select
Zhen = False
Exit For
End If
Next i
If Zhen Then Prc = Prc + "00"
lnP = Len(Prc)
For i = 1 To lnP
Tmp = Str(Mid(Prc, i, 1)) & Tmp
Next iZDX = ""
fy = 1
For i = 1 To lnP
Xx = Mid(Tmp, i, 1)
Dx = Mid(China, i, 1)If Xx <> "零" Then
ZDX = Xx & Dx & ZDX
f = 1
Else
If i = 3 Then
ZDX = Dx & ZDX
End IfIf i = 7 Then
ZDX = Dx & ZDX
End If
If f Then
ZDX = "零" & ZDX
End If
f = 0
End If
Next i
If Zhen Then ZDX = ZDX + "正"
ZDX = Replace(ZDX, "零万", "万")
ZDX = Replace(ZDX, "零元", "元")End Function
Dim n_data, num, c_data, n_str As String
Dim i, j, k, l As Long
num = L_num
n_data = String(14 - Len(Trim(CStr(Abs(num * 100)))), " ") + Trim(CStr(Abs(num) * 100))
For i = 1 To 14 Step 1
n_str = Mid(n_data, i, 1)
If n_str <> " " Then
If Mid(n_data, i, 2) = "00" Or (n_str = "0" And (i = 4 Or i = 8 Or i = 12 Or i = 14)) Then
Else
c_data = c_data + Trim(Mid("零壹贰叁肆伍陆柒捌玖", CInt(n_str) + 1, 1))
End If
If n_str = "0" And i <> 4 And i <> 8 And i <> 12 Then
Else
c_data = c_data + Trim(Mid("仟佰拾亿仟佰拾万仟佰拾圆角分", i, 1))
End If
If Right(c_data, 4) = "亿万" Then c_data = Left(c_data, Len(c_data) - 1)
End If
Next
If num < 0 Then c_data = "(负数)" + c_data
If num = 0 Then c_data = "零圆"
If n_str = "0" Then c_data = c_data + "整"
Int2Chn = c_data
End Function
Text2 = ZDX(Val(Text1.Text))
End Sub