VB程序设计:将阿拉伯数字转换成汉字数字

具体要求:
(1)设计程序:在文本框内输入数字,则起上方的标签内自动显示起对应的汉字数字。
(2)由于采用 的汉字较少,可以预先将起都存在字符串总共。
(3)为了实现“输入数字几显示汉字”,可以采用文本框的keypress时间。
(4)尽量采用调用VB提供字符串函数。如Cstr、Len、Mid

给你一个现成的,加两个控件,一个Label1,一个Text1:

Private Sub Form_Load()
'初始化设置
Text1.MaxLength = 16
Text1.Text = ""
Label1.Caption = ""
Label1.AutoSize = True
Label1.BorderStyle = 1
Label1.FontSize = 18
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) 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, Mid(StrEng, intCounter, 1) + 1, 1)
'若某位是零
If strTempCh = "零" And intLen <> 1 Then
'若后一个也是零,或零出现在倒数第1、5、9、13等位,则不显示汉字“零”
If Mid(StrEng, intCounter + 1, 1) = "0" Or (intLen - intCounter + 1) Mod 4 = 1 Then strTempCh = ""
Else
strTempCh = strTempCh & Trim(Mid(strSeqCh1, intLen - intCounter + 1, 1))
End If
'对于出现在倒数第1、5、9、13等位的数字
If (intLen - intCounter + 1) Mod 4 = 1 Then
'添加位" 万亿兆"
strTempCh = strTempCh & Trim(Mid(strSeqCh2, (intLen - intCounter) \ 4 + 1, 1))
End If
'组成汉字表达式
strCh = strCh & Trim(strTempCh)
Next
CChinese = strCh
End Function
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-10-24
  准备Text1控件,和Label1控件

  Private Sub Form_Load()
  Text1 = ""
  Label1.AutoSize = True
  End Sub

  Private Sub Text1_Change()
  Dim strCh As String, temp As String, i As Integer
  strCh = "零一二三四五六七八九"
  temp = ""
  For i = 1 To Len(Text1)
  temp = temp & Mid(strCh, CInt(Mid(Text1, i, 1)) + 1, 1)
  Next
  Label1.Caption = temp
  End Sub

  Private Sub Text1_KeyPress(KeyAscii As Integer)
  Select Case KeyAscii
  Case vbKeyBack
  Text1 = ""
  Case Is < Asc("0")
  KeyAscii = 0
  Case Is > Asc("9")
  KeyAscii = 0
  End Select
  End Sub本回答被网友采纳
第2个回答  2009-06-23
这不就是个选择的问题
在文本框的keypress事件里逐个取字符分析根据不同的字符选择输出不用的中文就可以了
第3个回答  2018-04-29
准备label,textbox控件。
textbox2.text=mid("零……玖",textbox.text+1,1)
相似回答