| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4227 人关注过本帖
标题:[求助]数字0-9转换成大写文字函数怎样写?
只看楼主 加入收藏
zhangsj
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-11-15
收藏
 问题点数:0 回复次数:14 
[求助]数字0-9转换成大写文字函数怎样写?
请教:在text控件中输入数字,怎样能用简单的程序把它转换成"一~十"的文字显示在另一控件中,谢谢
搜索更多相关主题的帖子: 函数 数字 文字 
2006-12-07 10:21
bestfeng
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:179
专家分:0
注 册:2006-10-31
收藏
得分:0 

Function change(Str As String)
Dim strlen As Integer
Dim i As Integer
Dim outStr As String
Dim inString As String
strlen = Len(Str)
For i = 1 To strlen
inString = Mid(Str, i, 1)
Select Case inString
Case "0"
outStr = "零"
Case "1"
outStr = "一"
Case "2"
outStr = "二"
Case "3"
outStr = "三"
Case "4"
outStr = "四"
Case "5"
outStr = "五"
Case "6"
outStr = "六"
Case "7"
outStr = "七"
Case "8"
outStr = "八"
Case "9"
outStr = "九 "
Case Else
outStr = inString
End Select
change = change + outStr




Next



End Function

2006-12-07 11:50
bestfeng
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:179
专家分:0
注 册:2006-10-31
收藏
得分:0 
如果2个textbox,则。。Private Sub Command1_Click()
Text2.Text = change(Text1.Text)

End Sub
2006-12-07 11:51
leon2
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:731
专家分:0
注 册:2005-3-18
收藏
得分:0 

改进一下二楼的:

Function change(Str As String)
Dim strlen As Integer
Dim i As Integer
Dim outStr As String
Dim inString As String
strlen = Len(Str)
For i = 1 To strlen
inString = Mid(Str, i, 1)
If IsNumeric(inString) Then
outStr = Choose(CInt(inString) + 1, "零", "一", "二", "三", "四", "五", "六", "七", "八", "九")
Else
outStr = inString
End If

End Select
change = change + outStr
Next
End Function

但你是要输入一个数字还是几个?如果是几个,上面的代码就管用;否则就用下面的

Function change(Str As String)
Dim outStr As String
If IsNumeric(Str) Then
outStr = Choose(CInt(Str) + 1, "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十")
Else
outStr = Str
End If
change = outStr
End Function

[此贴子已经被作者于2006-12-7 18:00:44编辑过]

2006-12-07 17:56
bestfeng
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:179
专家分:0
注 册:2006-10-31
收藏
得分:0 

谢谢改进,学习了

2006-12-07 17:58
死神不哭
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2006-11-17
收藏
得分:0 
太难了。。。但我要抄下来才行。做个笔记
2006-12-08 20:18
HaCk的旋律
Rank: 1
等 级:新手上路
威 望:1
帖 子:73
专家分:0
注 册:2006-12-1
收藏
得分:0 

高手们..我问一下问题...


为什么你们的变量命名好象都很复杂?


做我所想! 欢迎大家加我好友@ Mailto: buxchang@
2006-12-08 21:03
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
变量名..最好是一些见名知义的单词组合..
例如strLen,一看就知道是字符串长度的意思了..那假如你用个a来代码..你写一些比较简短的代码是..是比较方便..但你写得较长是..或许开发周期比较长时..很容易就会忘记它的意思...如果是团队开发..那其他程序员维护..也会增加很多麻烦..所以...长一些没所谓..最好保持在15个字符以内...

我的msn: myfend@
2006-12-08 21:17
slore
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1108
专家分:0
注 册:2005-7-1
收藏
得分:0 
Private Sub Command1_Click()
Dim context As String
context = Text1
For i = 1 To Len(context)
Index = Int(Mid(context, i, 1))
Mid(context, i, 1) = Mid("零一二三四五六七八九", Index + 1, 1)
Next
Text1 = context
End Sub

快上课了……
2006-12-08 21:59
hyhhd
Rank: 2
等 级:论坛游民
威 望:1
帖 子:502
专家分:44
注 册:2006-5-12
收藏
得分:0 

将9楼的改了一下:
Private Sub Command1_Click()
Text1 = StringToNember(Text1)

End Sub

Public Function StringToNember(StrValue As String) As String
Dim Context As String
Dim Index As Integer
Dim StrLen As Integer

Context = StrValue
StrLen = Len(Context)

For i = 1 To StrLen
Index = Int(Val(Mid(Context, i, 1)))
Mid(Context, i, 1) = Mid("零一二三四五六七八九", Index + 1, 1)

Next

StringToNember = Context

End Function

[此贴子已经被作者于2006-12-8 22:53:15编辑过]


2006-12-08 22:49
快速回复:[求助]数字0-9转换成大写文字函数怎样写?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038045 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved