主题:[讨论]诸位帮忙看看这个统计字符串中字母数字及标点符号等个数的小程序错在哪????
sharon850510
[专家分:0] 发布于 2005-09-23 23:46:00
程序设计以下 Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Application.Exit()
End Sub '返回到编辑状态
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
End Sub '清空命令程序
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s, temp As String
Dim sz, zm, bd, sf, kg, qt As Integer
Dim i, j As Integer
sz = 0 : zm = 0 : bd = 0 : sf = 0 : kg = 0 : qt = 0
i = Len(s)
TextBox1.Text = CStr(s)
For j = 1 To i Step 1
temp = Mid$(s, 1, i)
Select Case temp
Case "0" To "9"
sz = sz + 1
Case "a" To "p", "A" To "Z"
zm = zm + 1
Case ",", ".", ";", "!", "(", ")", "[", "]", "{", "}"
bd = bd + 1
Case "<", ">", "*", "+", "-", "/", "%"
sf = sf + 1
Case " "
kg = kg + 1
Case Else
qt = qt + 1
End Select
Next j
TextBox2.Text = TextBox2.Text & CStr(sz)
TextBox3.Text = TextBox3.Text & CStr(zm)
TextBox4.Text = TextBox4.Text & CStr(bd)
TextBox5.Text = TextBox5.Text & CStr(sf)
TextBox6.Text = TextBox6.Text & CStr(kg)
TextBox7.Text = TextBox7.Text & CStr(qt)
End Sub '按下统计按钮开始统计字符串中各种字符的个数
[em17][em17]
回复列表 (共9个回复)
沙发
sharon850510 [专家分:0] 发布于 2005-09-23 23:49:00
我试过好几次都不能调试成功
可我反复检查过几遍发现不了问题
还请各位仁兄帮忙
我这个困扰
板凳
sharon850510 [专家分:0] 发布于 2005-09-23 23:51:00
哪位高手看到烦请帮忙
急急
我试了好久了
3 楼
ryowu [专家分:6470] 发布于 2005-09-26 12:04:00
你这个是vb6的代码阿,照搬可不成
mid$在vb.net中好像没有哦
.net中使用string类的substring()方法来截取字符
4 楼
宝宝啊呜 [专家分:990] 发布于 2005-09-26 14:09:00
楼主,你的select case 语句根本就米被执行哦
5 楼
宝宝啊呜 [专家分:990] 发布于 2005-09-26 14:31:00
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s, temp As String
Dim sz, zm, bd, sf, kg, qt As Integer
Dim i, j As Integer
sz = 0 : zm = 0 : bd = 0 : sf = 0 : kg = 0 : qt = 0
i = TextBox1.Text.Trim.Length
For j = 1 To i Step 1
temp = TextBox1.Text.Substring(0, i)
Select Case temp
Case "0" To "9"
sz = sz + 1
Case "a" To "p", "A" To "Z"
zm = zm + 1
Case ",", ".", ";", "!", "(", ")", "[", "]", "{", "}"
bd = bd + 1
Case "<", ">", "*", "+", "-", "/", "%"
sf = sf + 1
Case " "
kg = kg + 1
Case Else
qt = qt + 1
End Select
Next
TextBox2.Text = sz
TextBox3.Text = zm
TextBox4.Text = bd
TextBox5.Text = sf
TextBox6.Text = kg
TextBox7.Text = qt
End Sub
这个比之前的好一点,但还是有问题的,再请高手们帮修改下吧
6 楼
5653325 [专家分:40] 发布于 2005-09-30 15:10:00
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s, temp As String
Dim sz, zm, bd, sf, kg, qt As Integer
Dim i, j As Integer
sz = 0 : zm = 0 : bd = 0 : sf = 0 : kg = 0 : qt = 0
i = Len(s)
TextBox1.Text = CStr(s)
'-----------------------------------------------
s从哪里得到参数?
7 楼
5653325 [专家分:40] 发布于 2005-09-30 15:27:00
我改了一下
你只保留textbox1和button1 然后用下面代码
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim NumCount As Integer '数字总数
Dim LStrCount As Integer '字符小写总数
Dim UStrCount As Integer '字符大写总数
Dim IntCount As Integer '标点符号总数
Dim i As Integer
'**********************************
'程序只统计英文状态下的字符数,如果需要统计中文请自己写
'************************************
For i = 0 To TextBox1.Text.Length - 1
Select Case Asc(TextBox1.Text.Substring(i, 1))
Case 97 To 122
LStrCount += 1
Case 65 To 90
UStrCount += 1
Case 48 To 57
NumCount += 1
Case Else
IntCount += 1
End Select
Next
MsgBox("字符串中共有:" & LStrCount & "个小写字符、" & UStrCount & "个大写字符、" & NumCount & "个数字和" & IntCount & "个其它字符。")
End Sub '按下统计按钮开始统计字符串中各种字符的个数
8 楼
zrs797246 [专家分:190] 发布于 2005-09-30 18:19:00
我看了一下,应该是mid$()里的参数错了,里面的参数该为两个试一下。
9 楼
yjlxy [专家分:0] 发布于 2006-05-16 21:21:00
'在VB6中的的程序是这样的。
Private Sub Command1_Click()
Dim temp As String, s As String
Dim sz, zm, bd, sf, kg, qt As Integer
Dim i, j As Integer
Cls
sz = 0: zm = 0: bd = 0: sf = 0: kg = 0: qt = 0
s = Text1.Text '获取文本框中的内容
i = Len(s)'求出内容的的长度
For j = 1 To i Step 1
temp = Mid$(s, j, 1)
Select Case temp
Case "0" To "9"
sz = sz + 1
Case "a" To "p", "A" To "Z"
zm = zm + 1
Case ",", ".", ";", "!", "(", ")", "[", "]", "{", "}"
bd = bd + 1
Case "<", ">", "*", "+", "-", "/", "%"
sf = sf + 1
Case " "
kg = kg + 1
Case Else
qt = qt + 1
End Select
Next j
MsgBox "数字个数:" & sz & "字母个数:" & zm & "标点个数:" & bd & "数学符号个数:" & sf & "空格个数:" & kg & "其它个数:" & qt
End Sub '单击统计开始执行[em1]
我来回复