找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 4139|回复: 0

[其它源码] 将阿拉伯数字转成中文字

[复制链接]

1214

主题

352

回帖

11

精华

管理员

菜鸟

积分
93755

贡献奖关注奖人气王精英奖乐于助人勋章

发表于 2010-8-8 14:54:16 | 显示全部楼层 |阅读模式
一个Form
               一个TextBox
               一个Label

  这个修订後的程式是当使用者在TextBox中输入只包含 0~9 的数值後,在Label中就可
  看见被转换後的中文字,例如:1560890 转成 "壹佰伍拾陆万零捌佰玖拾"。程式限制
  为不可输入超过16个数字。

  请建立一个新专案,并在表单中放入上述物件,再把以下程式码复制到表单的程式
  码视窗,最後按下F5来执行。

  Private Sub Form_Load()
       Text1.MaxLength = 16
       Text1.Text = ""
       Label1.Caption = ""
       Label1.AutoSize = True
       Label1.BorderStyle = 1
  End Sub

  Private Sub Text1_Change()
       Label1.Caption = CChinese(Text1.Text)
  End Sub

  Private Function CChinese(StrEng As String) As String
       If Not IsNumeric(StrEng) Or StrEng Like "*.*" Or StrEng Like "*-*" Then
            If Trim(StrEng) <> "" Then MsgBox "无效的数字"
            CChinese = "": Exit Function
       End If
       Dim intLen As Integer, intCounter As Integer
       Dim strCh As String, strTempCh As String
       Dim strSeqCh1 As String, strSeqCh2 As String
       Dim strEng2Ch As String
       strEng2Ch = "零壹贰叁肆伍陆柒捌玖"
       strSeqCh1 = " 拾佰仟 拾佰仟 拾佰仟 拾佰仟"
       strSeqCh2 = " 万亿兆"
       StrEng = CStr(CDec(StrEng))
       intLen = Len(StrEng)
       For intCounter = 1 To intLen
            strTempCh = Mid(strEng2Ch, Val(Mid(StrEng, intCounter, 1)) + 1, 1)
            If strTempCh = "零" And intLen <> 1 Then
                 If Mid(StrEng, intCounter + 1, 1) = "0" Or (intLen - intCounter + 1) Mod 4 = 1 Then
                      strTempCh = ""
                 End If
            Else
                 strTempCh = strTempCh & Trim(Mid(strSeqCh1, intLen - intCounter + 1, 1))
            End If
            If (intLen - intCounter + 1) Mod 4 = 1 Then
                 strTempCh = strTempCh & Mid(strSeqCh2, (intLen - intCounter + 1) \ 4 + 1, 1)
                 If intCounter > 3 Then
                      If Mid(StrEng, intCounter - 3, 4) = "0000" Then strTempCh = Left(strTempCh, Len(strTempCh) - 1)
                End If
            End If
            strCh = strCh & Trim(strTempCh)
       Next
       CChinese = strCh
  End Function
【VB】QQ群:1422505加的请打上VB好友
【易语言】QQ群:9531809  或 177048
【FOXPRO】QQ群:6580324  或 33659603
【C/C++/VC】QQ群:3777552
【NiceBasic】QQ群:3703755
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表