Results 1 to 2 of 2

Thread: Stop the searching under conditions ( Treeview )

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2009
    Posts
    364

    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:

    Last edited by Fraps; Sep 2nd, 2010 at 02:45 AM.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width