怎么理解这段vb代码?

来源:百度知道 编辑:UC知道 时间:2024/09/26 14:03:30
Private Sub Command1_Click()
Dim s As String, c As String
Dim slen As Integer, i As Integer
Dim sz As Integer, zm As Integer, qt As Integer
s = Text1.Text
slen = Len(s)
sz = 0 '记录数字字符数
zm = 0 '记录英文字母数
qt = 0 '记录其它字符数
For i = 1 To slen
c = LCase(Mid(s, i, 1))
If c >= "0" And c <= "9" Then
sz = sz + 1
Else
If c >= "a" And c <= "z" Then
zm = zm + 1
Else
qt = qt + 1
End If
End If
Next i
Text2.Text = sz
Text3.Text = zm
Text4.Text = qt
End Sub

Private Sub Command1_Click()
Dim s As String, c As String
Dim slen As Integer, i As Integer
Dim sz As Integer, zm As Integer, qt As Integer
s = Text1.Text
slen = Len(s)
sz = 0 '记录数字字符数
zm = 0 '记录英文字母数
qt = 0 '记录其它字符数
For i = 1 To slen '开始循环,以s所含字符数为上限
c = LCase(Mid(s, i, 1)) '将s串中的每一个字符依次单独取出并转换成小写[如果是字母的话]赋给串变量c
If c >= "0" And c <= "9" Then '如果c是数字0-9则执行下面语句
sz = sz + 1 '累计数字个数
Else If c >= "a" And c <= "z" Then '否则,如果c是字母则执行下面语句[注意:此处原来有语法错误!]
zm = zm + 1 '累计字母个数
Else '否则执行下面语句
qt = qt + 1 '累计其它字符个数
End If
End If [此处多余一个End If ]
Next i
'以下是分别将数字个数、字母个数、其它字符个数显示于3个文本框中
Text2.Text = sz
Text3.Text = zm
Text4.Text = qt
End Sub