求教VB题目5

来源:百度知道 编辑:UC知道 时间:2024/05/26 06:59:03
新建一个窗体,在窗体上加入4个文本框(设名称为Text1,Text2,Text3,Text4)和1个命令按纽(设名称为Command1)。程序运行时:在文本框Text1中输入1个字符串,单击Command1时,程序统计出输入字符串中数字字符个数、字母字符个数和其他字符个数,并将统计出来的结果分别显示到文本Text2,Text3,Text4中。

帮忙,拜托了,谢谢!!!

Private Sub Command1_Click()
dim i as long
dim p(1 to 3) as long
dim d as string
for i=1 to len(text1.text)
d=mid(text1.text,i,1)
if ucase(d)>="A" and ucase(d)<="z" then '大写a小写z
p(1)=p(1)+1
elseif d>="0" and d<="9" then
p(2)=p(2)+1
else
p(3)=p(3)+1
end if
next i
text2.text="字母有:" +cstr(p(1))+"个"
text3.text="数字有:" +cstr(p(2))+"个"
text.text="其它字符有:" +cstr(p(3))+"个"
End Sub

稍微修改了下

Private Sub Command1_Click()
dim i as long
dim p(1 to 3) as long
dim d as string
for i=1 to len(text1.text)
d=mid(text1.text,i,1)
if ucase(d)>="A" and ucase(d)<="Z" then
p(1)=p(1)+1
elseif d>="0" and d<="0" then
p(2)=p(2)+1
else