求高手幫我寫一個可以輸入數字轉成大寫國字
例: 打入1234 可以轉成 壹仟二佰三十四
可以轉換到億的單位~~~麻煩ㄌ 很急喔
如果不懂可以寫信問我 謝謝大大
2006-11-02 15:49:36 · 4 個解答 · 發問者 o(‧‧)o益 3 in 電腦與網際網路 ➔ 程式設計
Private Sub Command1_Click()
Dim w(10), z(10), r(10)
Dim result As String
word = Text1.Text
For i = 1 To Len(word)
w(i) = Mid(word, i, 1)
If w(i) = 0 Then r(i) = "零"
If w(i) = 1 Then r(i) = "壹"
If w(i) = 2 Then r(i) = "貳"
If w(i) = 3 Then r(i) = "參"
If w(i) = 4 Then r(i) = "肆"
If w(i) = 5 Then r(i) = "伍"
If w(i) = 6 Then r(i) = "陸"
If w(i) = 7 Then r(i) = "柒"
If w(i) = 8 Then r(i) = "捌"
If w(i) = 9 Then r(i) = "玖"
Next i
z(8) = ("千萬")
z(7) = ("百萬")
z(6) = ("十萬")
z(5) = ("萬")
z(4) = ("千")
z(3) = ("百")
z(2) = ("十")
result = " "
L = Len(word)
For i = 1 To Len(word)
Print r(i); z(L);
L = L - 1
Next i
End Sub
2006-11-02 20:03:51 · answer #1 · answered by ? 5 · 0⤊ 0⤋
天啊!看到Liu-Liu大大的程式碼真的讓我嚇一大跳..
六年前我還在某公家機關當工讀生時..
當時因為還是直式公文,所以也寫了一個數字轉中文的函數..
那時的想法和寫法,和Liu-Liu大超相似...
不過我測的結果是和WJS大一樣,因為當時是以Excel轉換出來的結果來寫的...
程式碼:
http://specterglobe.myweb.hinet.net/numtochr.txt
我多加了N參數來決定用"二"或"貳"系統,及增加小數轉換的功能..
2006-11-04 09:43:47 補充:
慚愧!那時還不懂得使用InStr函數,所以抓小數點是用For+Mid來抓..
2006-11-04 04:41:47 · answer #2 · answered by 幽靈 5 · 0⤊ 0⤋
死Liu-Liu,給偶吐槽XD
2006-11-03 11:45:16 · answer #3 · answered by W.J.S. 7 · 0⤊ 0⤋
Option ExplicitPrivate Sub Form_Activate() Text1.Text = ""End SubPrivate Sub Text1_Change() Dim c1() Dim c2() Dim c3() Dim i As Integer Dim j As Integer Dim ansstr As String c1 = Array("零", "壹", "貳", "參", "肆", "伍", "陸", "柒", "捌", "玖") c2 = Array("", "拾", "佰", "仟") c3 = Array("", "萬", "億", "兆", "京") Cls Print Print Print ansstr = "" For i = 1 To Len(Text1.Text) If Mid(Text1.Text, i, 1) <> "0" Then If i > 2 And (Len(Text1.Text) - i + 1) Mod 4 <> 0 Then If Mid(Text1.Text, i - 1, 1) = "0" Then ansstr = ansstr + "零" End If ansstr = ansstr + c1(Val(Mid(Text1.Text, i, 1))) ansstr = ansstr + c2((Len(Text1.Text) - i) Mod 4) End If If (Len(Text1.Text) - i) Mod 4 = 0 And InStr("萬億兆京", Right(ansstr, 1)) = 0 Then ansstr = ansstr + c3((Len(Text1.Text) - i) \ 4) Next Print ansstrEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then If KeyAscii <> 8 Then KeyAscii = 0 End If End If If Text1.SelStart = 0 And KeyAscii = Asc("0") Then KeyAscii = 0 End IfEnd Sub
2006-11-03 15:47:11 補充:
用 102030405060 測試結果:
WJS:壹仟零貳拾億零參仟零肆拾萬零伍仟零陸拾
Liu-Liu:壹仟零貳拾億參仟零肆拾萬伍仟零陸拾
2006-11-03 10:34:47 · answer #4 · answered by 世賢 7 · 0⤊ 0⤋