编程的小问题请教大家!!

splory 2005-08-31 08:16:01
我编的程序如下:
Private Sub Command1_Click()
Dim b(9), c(9) As String
Dim a As String, n As Integer, s As String
c(1) = "": c(2) = "拾": c(3) = "佰": c(4) = "千": c(5) = "万":
c(6) = "拾": c(7) = "百": c(8) = "千": c(9) = "亿"
b(0) = "": b(1) = "壹": b(2) = "贰": b(3) = "叁": b(4) = "肆":
b(5) = "伍": b(6) = "陆": b(7) = "柒": b(8) = "捌": b(9) = "玖"
a = Text1.Text
For i = Len(a) To 1 Step -1
n = Mid(a, Len(a) + 1 - i, 1)
If n = 0 And i <> 5 Then
c(i) = ""
End If
s = s & b(n) & c(i)
Next i
Label3.Caption = s & "元整"
End Sub

得到的结果有些有点问题:象输入00000得到的结果是:万元整;想得到的结果 是没有那个万字!
...全文
113 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
mikewolf_sky 2005-08-31
  • 打赏
  • 举报
回复
netone04(思想無疆) 回答的确有道理,确实是你要得到的答案。
Private Sub Command1_Click()
Dim b(9), c(9) As String
Dim a As String, n As Integer, s As String
c(1) = "": c(2) = "拾": c(3) = "佰": c(4) = "千": c(5) = "万":
c(6) = "拾": c(7) = "百": c(8) = "千": c(9) = "亿"
b(0) = "": b(1) = "壹": b(2) = "贰": b(3) = "叁": b(4) = "肆":
b(5) = "伍": b(6) = "陆": b(7) = "柒": b(8) = "捌": b(9) = "玖"
a = Text1.Text
If Left(a, 1) = "0" Then
Label1.Caption = " "
Else
For i = Len(a) To 1 Step -1
n = Mid(a, Len(a) + 1 - i, 1)
If n = 0 And i <> 5 Then
c(i) = ""
End If
s = s & b(n) & c(i)
Next i
End If
Label3.Caption = s & "元整"
End Sub
深圳小武 2005-08-31
  • 打赏
  • 举报
回复
因為這句If n = 0 And i <> 5 Then i不等於5決定了保留萬這個單位,所以有你這個錯誤。為什麼不加個條件呢?在for 語句之前加個條件。修改部分如下
a = Text1.Text
If Left(a, 1) = "0" Then
Else
For i = Len(a) To 1 Step -1
n = Mid(a, Len(a) + 1 - i, 1)
If n = 0 And i <> 5 Then
c(i) = ""
End If
s = s & b(n) & c(i)
Next i
End If
Label3.Caption=s & "元整"
缪军 2005-08-31
  • 打赏
  • 举报
回复
楼主试试这个
Public Function dfTransToBig(ByVal curMoney As Variant) As String
On Error GoTo ErrTrap
If Not IsNumeric(curMoney) Then
Exit Function
End If
dfTransToBig = ""

Dim strMoney As String
Dim strInt As String
Dim strDec As String
Dim strTemp As String

strMoney = Format(Str(curMoney), "#.00")
strInt = Left(strMoney, Len(strMoney) - 3)
strInt = String(12 - Len(strInt), "0") & Trim(strInt)
strDec = Right(strMoney, 2)

strTemp = dfGroupToBig(Mid(strInt, 1, 4))
If strTemp <> "" Then
dfTransToBig = dfTransToBig & strTemp & "亿"
End If

strTemp = dfGroupToBig(Mid(strInt, 5, 4))
If strTemp <> "" Then
dfTransToBig = dfTransToBig & strTemp & "万"
End If

strTemp = dfGroupToBig(Mid(strInt, 9, 4))
If strTemp <> "" Then
dfTransToBig = dfTransToBig & strTemp
End If

dfTransToBig = dfTransToBig & "圆"
If strDec = "00" Then
dfTransToBig = dfTransToBig & "整"
Else
If Left(strDec, 1) = "0" Then
dfTransToBig = dfTransToBig & dfNumberToBig(Right(strDec, 1)) & "分"
Else
If Right(strDec, 1) = "0" Then
dfTransToBig = dfTransToBig & dfNumberToBig(Left(strDec, 1)) & "角"
Else
dfTransToBig = dfTransToBig & dfNumberToBig(Left(strDec, 1)) & "角" & dfNumberToBig(Right(strDec, 1)) & "分"
End If
End If
End If
Exit Function
ErrTrap:
On Error GoTo 0
End Function
splory 2005-08-31
  • 打赏
  • 举报
回复
benyfeifei(狒狒) 最先那样做我试过了
但又会有新的问题出现,比如输入500000,得到的是:五十元整!!!


没有想到你下面那个程序这么长阿!
benyfeifei 2005-08-31
  • 打赏
  • 举报
回复
一个比较完整的金额转换程序:
Function BigMoney(money)
Dim x, y,i
Const zimu = ".sbqwsbqysbqwsbq"
Const letter ="0123456789sbqwy.zjf"
Const upcase = "零壹贰叁肆伍陆柒捌玖拾佰仟萬億圆整角分"
Dim temp

temp = money

If InStr(temp, ".")> 0 Then temp = Left(temp, InStr(temp, ".") - 1)

If Len(temp)>16 Then '只能转换一亿亿元以下数目的货币!
BigMoney= "数目太大,无法换算!请输入一亿亿以下的数字"
Exit Function
end if
'x = Format(money,"0.00") '格式化货币
x=FormatNumber(money,2,,,0)
'x=money
y = ""

For i = 1 To Len(x) - 3
y =y & Mid(x, i, 1) & Mid(zimu, Len(x) - 2 - i, 1)
Next


If Right(x,3)=".00" then
y=y & "z"
Else
y=y & left(Right(x,2),1) & "j" & Right(x,1) & "f"
End if

y = Replace(y,"0q","0") '避免零千(如:40200肆萬零千零贰佰)
y = Replace(y,"0b","0") '避免零百(如:41000肆萬壹千零佰)
y = Replace(y,"0s","0") '避免零十(如:204贰佰零拾零肆)

Do While y <> Replace(y,"00","0")
y = Replace(y,"00","0") '避免双零(如:1004壹仟零零肆)
Loop

y = Replace(y,"0y","y") '避免零億(如:210億贰佰壹十零億)

y = Replace(y,"0w","w") '避免零萬(如:210萬贰佰壹十零萬)

if Len(x) = 5 And Left(y,1) = "1" then

y=Right(y,Len(y) - 1)
end if
'y = IIf(Len(x) = 5 And Left(y, 1) = "1", Right(y, Len(y) - 1), y) '避免壹十(如:14壹拾肆;10壹拾)

'y =IIf(Len(x) = 4, Replace(y, "0.", ""), Replace(y, "0.", ".")) '避免零元(如:20.00贰拾零圆;0.12零圆壹角贰分)
if Len(x) = 4 then

y=Replace(y,"0.","")
else
y= Replace(y,"0.",".")
end if
For i = 1 To 19
y = Replace(y,Mid(letter,i,1), Mid(upcase,i,1)) '大写汉字
Next

BigMoney = y
End Function
province_ 2005-08-31
  • 打赏
  • 举报
回复
得到的根本不是正规的大写数字。很早以前写过一个,等我找找。
benyfeifei 2005-08-31
  • 打赏
  • 举报
回复
程序修改如下:
Private Sub Command1_Click()
Dim b(9), c(9) As String
Dim a As String, n As Integer, s As String
c(1) = "": c(2) = "拾": c(3) = "佰": c(4) = "千": c(5) = "万":
c(6) = "拾": c(7) = "百": c(8) = "千": c(9) = "亿"
b(0) = "": b(1) = "壹": b(2) = "贰": b(3) = "叁": b(4) = "肆":
b(5) = "伍": b(6) = "陆": b(7) = "柒": b(8) = "捌": b(9) = "玖"
a = Text1.Text
For i = Len(a) To 1 Step -1
n = Mid(a, Len(a) + 1 - i, 1)
If n = 0 Then
c(i) = ""
End If
s = s & b(n) & c(i)
Next i
Label3.Caption=s & "元整"
End Sub

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧