vb实例教程(一个查找程序)
界面如图,运行时在文本框text1中输入要查找的内容,单击“开始查找”按钮开始在文本框text2中查找,找到时,将找到的内容选中,“开始查找”按钮变为“查找下一个”,单击...
界面如图,运行时在文本框text1中输入要查找的内容,单击“开始查找”按钮开始在文本框text2中查找,找到时,将找到的内容选中,“开始查找”按钮变为“查找下一个”,单击“查找下一个”按钮继续查找。但在text2中查找结束后,弹出信息对话框,显示找到的个数。
展开
2个回答
展开全部
Dim a As Integer
Dim b As Integer
Private Sub Command1_Click()
k = InStr(a, Text2, Text1)
If k > 0 Then
Command1.Caption = "查找下一个"
a = k + Len(Text1)
Text2.SetFocus
Text2.SelStart = k - 1
Text2.SelLength = Len(Text1)
b = b + 1
Else
MsgBox "查找完毕!共找到 " & b & " 个 " & Text1
Command1.Caption = "查找"
a = 1
End If
'Print k
End Sub
Private Sub Form_Load()
Label1 = "要查找的内容:"
Command1.Caption = "查找"
a = 1
End Sub
Dim b As Integer
Private Sub Command1_Click()
k = InStr(a, Text2, Text1)
If k > 0 Then
Command1.Caption = "查找下一个"
a = k + Len(Text1)
Text2.SetFocus
Text2.SelStart = k - 1
Text2.SelLength = Len(Text1)
b = b + 1
Else
MsgBox "查找完毕!共找到 " & b & " 个 " & Text1
Command1.Caption = "查找"
a = 1
End If
'Print k
End Sub
Private Sub Form_Load()
Label1 = "要查找的内容:"
Command1.Caption = "查找"
a = 1
End Sub
追问
Text2.SelLength = Len(Text1)
MsgBox "查找完毕!共找到 " & b & " 个 " & Text1
应该是text1.text
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询