请问vb中的一道求单词个数的题目

来源:百度知道 编辑:UC知道 时间:2024/06/05 08:52:27
Dim s1 As String
Dim i, num, tag As Integer
Dim m As Long
i = 1
tag = 1: num = 0
s1 = "I am a student!"
Print Len(s1)
Do While i <= Len(s1)
m = Mid(s1, i, 1)
If m >= "a" And m <= " z" Then
num = num + 1
tag = 0
Else
If tag = 1 Then
tag = 0
End If
End If
Loop
MsgBox "单词的个数是:" + CStr(num)

End Sub
我这样写理论上行否!它不能运行,各位大侠帮一下忙!

错误较多,修改如下:
Dim s1 As String
Dim i, num, tag As Integer
Dim m As String
i = 1
tag = 1: num = 0
s1 = "I am a student!"
Print Len(s1)
For i = 1 To Len(s1)
m = LCase(Mid(s1, i, 1))
If m >= "a" And m <= "z" Then
num = num + 1
tag = 0
Else
If tag = 1 Then
tag = 0
End If
End If
Next
MsgBox "单词的个数是:" + CStr(num)

你那是计算字母个数··