算法说明:
1)英语单词存放在数组words中。
2)如果在数组words中找到要查找的单词,则在标签Label4中显示“查找成功!”,并显示单词在数组words中出现的次数,如果未找到则显示“无此单词,请重输!”。
实现上述功能的VB程序如下,请在程序划线处填入合适的语句。
Dim n As Integer
Dim words(1 To 100) As String
Private Sub Command1_Click()
Dim key As String, i As Integer, times As Integer
key = Text1.Text
times = 0
For i = 1 To n
If key=words(i) Then
Next i
If times > 0 Then
Label4.Caption=“查找成功!共找到”+ +“个”
Else
Label4.Caption = “无此单词,请重输!”
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim word As String
word = Text1.Text
If KeyAscii = 13 Then
n = n + 1
List1.AddItem Str(n) + “:” + word
Text1.Text = “ ”
End If
End Sub