Stop the searching under conditions ( Treeview )
Hi,
thanks to LaVolpe which sent me a great code to search the treeview I have another short question.
Can you take a look at the code, and tell me is there any possible to stop the searching if program will find node.text = STOP? after one click if TEST node has been found.
My treeview contains "the chapters" - groups of the nodes. Each of them has STOP node at the end. I wanna to stop the program if find position will get the last line of the chapter ( equal to STOP node ).
Is there any way?
Code:
Code:
Public Sub Command5_Click()
Dim NrLoops As Integer, iLastItem As Integer, iFirstItem As Integer
Dim i As Integer
Dim Searcher As String
Dim Searcher2 As String
Dim FindPos As Integer
Dim found As Boolean
Searcher = "TEST"
iLastItem = TreeView5.Nodes.Count
If TreeView5.SelectedItem Is Nothing Then ' start from top
iFirstItem = 1
Else
iFirstItem = TreeView5.SelectedItem.Index + 1 ' start on row after one selected
If iFirstItem > iLastItem Then iFirstItem = 1 ' at bottom of list, start from top
End If
For NrLoops = 0 To 1
For i = iFirstItem To iLastItem
FindPos = InStr(1, TreeView5.Nodes(i).Text, Searcher, vbTextCompare)
If FindPos <> 0 Then
TreeView5.SetFocus
Set TreeView5.SelectedItem = TreeView5.Nodes(i)
TreeView5.SelectedItem.EnsureVisible
found = True ' no longer needed. If FindPos=0 then found=false
Exit For
End If
Next i
If FindPos = 0 Then
iLastItem = iFirstItem - 1
iFirstItem = 1
Else
Exit For
End If
Next NrLoops
If FindPos = 0 Then MsgBox ("Not found")
End Sub
My treeview:
http://img507.imageshack.us/img507/8308/treew.jpg
Re: Stop the searching under conditions ( Treeview )
I'd like to help, but I just don't understand.
1. You click the button & TEST is found
2. If it is found, you don't want the search function active any longer? If not, disable the button.
Maybe you can tell us in different words when the search function should be disabled and when it should not be disabled.
The search function you have exits when a match is found, it does not keep looping.