Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 X = Split(" ,拾,佰,仟,萬,拾,佰,仟,億,拾,佰,仟,兆", ",") Do While Not EOF(1) Input #1, N ans = "" K = 0 For i = Len(N) To 1 Step -1 ans = Mid(N, i, 1) & X(K) & ans K = K + 1 Next i
ans = Replace(ans, "1", "壹") ans = Replace(ans, "2", "貳") ans = Replace(ans, "3", "參") ans = Replace(ans, "4", "肆") ans = Replace(ans, "5", "伍") ans = Replace(ans, "6", "陸") ans = Replace(ans, "7", "柒") ans = Replace(ans, "8", "捌") ans = Replace(ans, "9", "玖") ans = Replace(ans, "0", "零") ans = Replace(ans, "零拾", "零") ans = Replace(ans, "零佰", "零") ans = Replace(ans, "零仟", "零") ans = Replace(ans, "零萬", "零") ans = Replace(ans, "零零零零", "零") ans = Replace(ans, "零零零", "零") ans = Replace(ans, "零零", "零") ans = Replace(ans, " ", "")
If Mid(ans, Len(ans), 1) = "零" Then ans = Mid(ans, 1, Len(ans) - 1) Print #2, "新台幣" & ans & "元整" Loop Close #2 Close #1
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(" ,拾,佰,仟,萬,拾,佰,仟,億,拾,佰,仟,兆", ",")
Do While Not EOF(1)
Input #1, N
ans = ""
K = 0
For i = Len(N) To 1 Step -1
ans = Mid(N, i, 1) & X(K) & ans
K = K + 1
Next i
ans = Replace(ans, "1", "壹")
ans = Replace(ans, "2", "貳")
ans = Replace(ans, "3", "參")
ans = Replace(ans, "4", "肆")
ans = Replace(ans, "5", "伍")
ans = Replace(ans, "6", "陸")
ans = Replace(ans, "7", "柒")
ans = Replace(ans, "8", "捌")
ans = Replace(ans, "9", "玖")
ans = Replace(ans, "0", "零")
ans = Replace(ans, "零拾", "零")
ans = Replace(ans, "零佰", "零")
ans = Replace(ans, "零仟", "零")
ans = Replace(ans, "零萬", "零")
ans = Replace(ans, "零零零零", "零")
ans = Replace(ans, "零零零", "零")
ans = Replace(ans, "零零", "零")
ans = Replace(ans, " ", "")
If Mid(ans, Len(ans), 1) = "零" Then ans = Mid(ans, 1, Len(ans) - 1)
Print #2, "新台幣" & ans & "元整"
Loop
Close #2
Close #1
End
End Sub
輸入:in.txt
123456789
999999999
900000001
900010001
1234
123456
輸出:out.txt
新台幣壹億貳仟參佰肆拾伍萬陸仟柒佰捌拾玖元整
新台幣玖億玖仟玖佰玖拾玖萬玖仟玖佰玖拾玖元整
新台幣玖億零壹元整
新台幣玖億零壹萬零壹元整
新台幣壹仟貳佰參拾肆元整
新台幣壹拾貳萬參仟肆佰伍拾陸元整
佑好,
回覆刪除程式正確。
在取代零的地方,原來也可以兩個零取代成一個零,但是,需要重複幾次,你用這樣4個3個2個,一次性去掉很多個,但是,有沒有漏網之魚呢?
while instr(ans,"零零") <> 0
ans=replace(ans,"零零","零")
wend
這樣是不是更安全呢。
1000100001
回覆刪除答案 : 壹拾億零壹拾萬零壹圓整
1010001000
答案 : 壹拾億零壹仟萬零壹仟圓整
樓上的程式碼執行這些會有錯