查找的问题

ccbbcc 2020-02-24 04:18:42
加精

我想实现上述功能,点击查找,弹出查找对话框,输入查找内容,点击查找按钮(这几步我都会),下面不会
第一个含有查找内容的一行显示为蓝色,再次点击查找按钮,第二个含有查找内容的一行显示为蓝色。
主要是查找算法不太会。
请高手指教,谢谢!
...全文
482 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2020-02-26
  • 打赏
  • 举报
回复
引用 5 楼 ccbbcc 的回复:
非常感谢!不过有个错误: msgbox("已经到达底部,是否从头开始查找", "询问", vbyesno) 这个要改成 msgbox("已经到达底部,是否从头开始查找", vbyesno ,"询问")
嗯,手写的,你明白意思就可以
ccbbcc 2020-02-26
  • 打赏
  • 举报
回复
非常感谢!不过有个错误:
msgbox("已经到达底部,是否从头开始查找", "询问", vbyesno)
这个要改成
msgbox("已经到达底部,是否从头开始查找", vbyesno ,"询问")
threenewbee 2020-02-25
  • 打赏
  • 举报
回复
完整代码下载:https://download.csdn.net/download/caozhy/12190310

Option Explicit

Dim WithEvents findDialog As findDialog

Private Sub Command1_Click()
List1.AddItem Text1
End Sub

Private Sub Command2_Click()
If findDialog Is Nothing Then Set findDialog = New findDialog
findDialog.Show , Me
End Sub

Private Sub findDialog_OnFind(ByVal s As String)
Dim curr As Integer
Dim i As Integer
curr = List1.ListIndex
For i = curr + 1 To List1.ListCount - 1
If InStr(1, List1.List(i), s) > 0 Then
List1.ListIndex = i
Exit Sub
End If
Next
For i = 0 To curr
If InStr(1, List1.List(i), s) > 0 Then
List1.ListIndex = i
Exit Sub
End If
Next
MsgBox "没找到"
End Sub




Option Explicit

Public Event OnFind(ByVal s As String)

Private Sub Command1_Click()
RaiseEvent OnFind(Text1.Text)
Me.SetFocus
End Sub



threenewbee 2020-02-25
  • 打赏
  • 举报
回复

Private Sub findDialog_OnFind(ByVal s As String)
Dim curr As Integer
Dim i As Integer
curr = List1.ListIndex
For i = curr + 1 To List1.ListCount - 1
If InStr(1, List1.List(i), s) > 0 Then
List1.ListIndex = i
Exit Sub
End If
Next
if msgbox("已经到达底部,是否从头开始查找", "询问", vbyesno) = vbno then exit sub
For i = 0 To curr
If InStr(1, List1.List(i), s) > 0 Then
List1.ListIndex = i
Exit Sub
End If
Next
MsgBox "没找到"
End Sub
ccbbcc 2020-02-25
  • 打赏
  • 举报
回复
谢谢!你这个代码很好。我比较满意。
不过,你这个代码如果能找到,会不停的查找。
能不能那样,从头查到尾之后,如果有,在到达尾部时提示已到文件末尾

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧