小张老师给同学们写了一个小程序来让同学们体验模糊查找。在List1中已经有了某班学生的姓名。从text1中输入要查找的关键字,点击command1查找按钮,从List2中能列出带有要查关键字的所有姓名。
程序代码如下:
Private Sub Command1_Click()
Dim Sname As String, Skey As String ‘Sname 保存姓名,Skey保存关键字
Dim i As Integer, j As Integer, n As Integer ‘n关键字的长度
Skey = Text1.Text
n = Len(Skey)
List2.Clear
For i = 1 To List1.ListCount ‘ListCount是列表框中项目的个数
Sname = List1.List(i - 1) ‘将List1中的第i-1项赋值给Sname
For j = 1 To ①
If Skey = ② Then
List2.AddItem Sname
Exit For
End If
Next j
Next i
If ③ = 0 Then List2.AddItem "没有找到带<" & Skey & ">的名字。"
End Sub