vb中如何编程实现点击 按钮可分别统计出文本框中数字、字母及其他字符的数量,并用消息框显示结果???
展开全部
intNum=0
intChar=0
intOther=0
for i=0 to len(text1)-1
testChar=asc(mid(text1.text,i,1))
if (testChar>=97 and testChar <=122) or (testChar>=65 and testChar <=90) then
intChar=intChar+1
elseif (testChar>=48 and testChar <=57) then
intNum=intNum+1
else
intOther=intOther+1
end if
next
msgbox("数字个数:"+intNum+",字母个数:"+intChar+",其他字符个数:"+intOther)
intChar=0
intOther=0
for i=0 to len(text1)-1
testChar=asc(mid(text1.text,i,1))
if (testChar>=97 and testChar <=122) or (testChar>=65 and testChar <=90) then
intChar=intChar+1
elseif (testChar>=48 and testChar <=57) then
intNum=intNum+1
else
intOther=intOther+1
end if
next
msgbox("数字个数:"+intNum+",字母个数:"+intChar+",其他字符个数:"+intOther)
追问
为什么运行错误呢?????
追答
不好意思我没调试,以下是正确的程序
Private Sub Command1_Click()
intNum = 0
intChar = 0
intOther = 0
For i = 1 To Len(Text1)
testChar = Asc(Mid(Text1.Text, i, 1))
If (testChar >= 97 And testChar = 65 And testChar = 48 And testChar <= 57) Then
intNum = intNum + 1
Else
intOther = intOther + 1
End If
Next
msgbox("数字个数:"&intNum&",字母个数:"&intChar&",其他字符个数:"&intOther)
End Sub
这个你都不会写啊?你干啥的啊?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询