Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 x = Split(",拾,佰,仟,萬,拾,佰,仟,億,拾,佰,仟,兆", ",") y = Split("零,壹,貳,參,肆,伍,陸,柒,捌,玖", ",") Do Input #1, num For i = Len(num) To 1 Step -1 If (Len(num) - i <> 0) And Val(Mid(num, i, 1)) <> 0 Then ans = y(Mid(num, i, 1)) & x(Len(num) - i) & ans Next ans = "新台幣" & ans & "元整" ans = Replace(ans, "零拾", "零") ans = Replace(ans, "零佰", "零") ans = Replace(ans, "零仟", "零") ans = Replace(ans, "零零", "零") Print #2, ans ans = "" Loop Until EOF(1) Close #2 Close #1 End End Sub
Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 x = Split(",拾,佰,仟,萬,拾,佰,仟,億,拾,佰,仟,兆", ",") y = Split("零,壹,貳,參,肆,伍,陸,柒,捌,玖", ",") Do Input #1, num For i = Len(num) To 1 Step -1 ans = y(Mid(num, i, 1)) & x(Len(num) - i) & ans Next If Mid(ans, Len(ans), 1) = "零" Then ans = Left(ans, Len(ans) - 1) ans = Replace(ans, "零拾", "零") ans = Replace(ans, "零佰", "零") ans = Replace(ans, "零仟", "零") ans = Replace(ans, "零零", "零") ans = "新台幣" & ans & "元整" Print #2, ans ans = "" Loop Until EOF(1) Close #2 Close #1 End End Sub
Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 a = Split(" ,拾,佰,仟,萬,拾,佰,仟,億,拾,佰,仟,兆", ",") b = Split("零,壹,貳,參, 肆,伍,陸,柒,捌,玖", ",") Do While Not EOF(1) msg = "": r = 0 Input #1, n For i = Len(n) To 1 Step -1 msg = b(Val(Mid(n, i, 1))) & a(r) & msg r = r + 1: msg = Replace(msg, " ", "") Next i For i = 1 To 4 msg = Replace(msg, b(0) & a(i), b(0)) msg = Replace(msg, a(i) & b(0), a(i)) Next i For i = 1 To Len(n) msg = Replace(msg, b(0) & b(0), b(0)) Next i msg = "新台幣" & msg & "元整" For i = 1 To 4 msg = Replace(msg, a(i) & b(0) & "元", a(i) & "元") Next i Print #2, msg Loop Close #2 Close #1 End End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
x = Split(",拾,佰,仟,萬,拾,佰,仟,億,拾,佰,仟,兆", ",")
y = Split("零,壹,貳,參,肆,伍,陸,柒,捌,玖", ",")
Do
Input #1, num
For i = Len(num) To 1 Step -1
If (Len(num) - i <> 0) And Val(Mid(num, i, 1)) <> 0 Then ans = y(Mid(num, i, 1)) & x(Len(num) - i) & ans
Next
ans = "新台幣" & ans & "元整"
ans = Replace(ans, "零拾", "零")
ans = Replace(ans, "零佰", "零")
ans = Replace(ans, "零仟", "零")
ans = Replace(ans, "零零", "零")
Print #2, ans
ans = ""
Loop Until EOF(1)
Close #2
Close #1
End
End Sub
經過測試,您的程式碼似乎有錯
回覆刪除程式有錯。
回覆刪除在判斷的地方要在多想想。
也記得仔細看程式執行後輸出結果是否正確。
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
x = Split(",拾,佰,仟,萬,拾,佰,仟,億,拾,佰,仟,兆", ",")
y = Split("零,壹,貳,參,肆,伍,陸,柒,捌,玖", ",")
Do
Input #1, num
For i = Len(num) To 1 Step -1
ans = y(Mid(num, i, 1)) & x(Len(num) - i) & ans
Next
If Mid(ans, Len(ans), 1) = "零" Then ans = Left(ans, Len(ans) - 1)
ans = Replace(ans, "零拾", "零")
ans = Replace(ans, "零佰", "零")
ans = Replace(ans, "零仟", "零")
ans = Replace(ans, "零零", "零")
ans = "新台幣" & ans & "元整"
Print #2, ans
ans = ""
Loop Until EOF(1)
Close #2
Close #1
End
End Sub
測資要多一點,你的程式碼執行結果如下
回覆刪除(以後要用一些較特別的測資)
in:
10000
0
1001
1503785
1500000
out:
新台幣壹萬零零元整
新台幣元整
新台幣壹仟零壹元整
新台幣壹佰伍拾零萬參仟柒佰捌拾伍元整
新台幣壹佰伍拾零萬零零元整
正確輸出應為
新台幣壹萬元整
新台幣零元整
新台幣壹仟零壹元整
新台幣壹佰伍拾萬參仟柒佰捌拾伍元整
新台幣壹佰伍拾萬元整
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
a = Split(" ,拾,佰,仟,萬,拾,佰,仟,億,拾,佰,仟,兆", ",")
b = Split("零,壹,貳,參, 肆,伍,陸,柒,捌,玖", ",")
Do While Not EOF(1)
msg = "": r = 0
Input #1, n
For i = Len(n) To 1 Step -1
msg = b(Val(Mid(n, i, 1))) & a(r) & msg
r = r + 1: msg = Replace(msg, " ", "")
Next i
For i = 1 To 4
msg = Replace(msg, b(0) & a(i), b(0))
msg = Replace(msg, a(i) & b(0), a(i))
Next i
For i = 1 To Len(n)
msg = Replace(msg, b(0) & b(0), b(0))
Next i
msg = "新台幣" & msg & "元整"
For i = 1 To 4
msg = Replace(msg, a(i) & b(0) & "元", a(i) & "元")
Next i
Print #2, msg
Loop
Close #2
Close #1
End
End Sub