Results 1 to 9 of 9

Thread: little help?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    83

    little help?

    I'm trying to create a text search, note that all variables are defined even if they aren't listed here

    if i type for example "hi hi hi hi hi" then click search it will find and highlight the first one, then i click it again and it finds the second, then when i click it again it finds the second again any help?

    here is the code:

    Code:
    Dim searched, newsearch As Long
    Private Sub cmdSearch_Click()
    searchtext = txtSearch.Text
    newsearch = searchpos + Len(searchtext)
    If searched = 0 Then searchpos = InStr(frmMain.txtNotepad.Text, frmSearch.txtSearch.Text)
    If searched = 1 Then searchpos = InStr(newsearch, frmMain.txtNotepad.Text, frmSearch.txtSearch.Text)
    If searchpos > 0 Then
    frmMain.txtNotepad.SetFocus
    searchlen = Len(searchtext)
    frmMain.txtNotepad.SelStart = searchpos - 1
    frmMain.txtNotepad.SelLength = searchlen
    End If
    searched = 1
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        
        Select Case UnloadMode
            Case vbFormControlMenu
    searched = 0
        End Select
    End Sub
    mail me at [email protected] if you need more specifics but can help me

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Set the instr() 'from' param to textbox.seltext + 1

    This way the search will always start from after the current curser position. after a search the curser will move to the found text to a second search can start from there.

    If the intention is to be able to move the curser yet continue from the same point then set a public variable to textbox.seltext + 1 after a search and search from there each time.

    Put an if statement in at the begining so that the variable is less than 1 or greater than len(text) to avoid errors


  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    There's also a demo project on my page showing how to find text using InStr and highlighting it... (misc section)

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    83

    uh....

    I don't think there is a .seltext property for txt boxes.... at least my VB(6.0) doesn't awknowledge it.

    It gives me a type mismatch error...?

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    As I remember RichTextBoxes have...

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    83

    I'm not usin rich text box(at least for now)

    I'm not usin rich text box(at least for now)

  7. #7
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136

    Lightbulb


    I don't think there is a .seltext property for txt boxes.... at least my VB(6.0) doesn't awknowledge it.
    Try:-
    Code:
    With txtNotepad
        newsearch = .SelStart + .SelLength + 1    
    End With

  8. #8
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Thumbs up

    My demo uses a simple text box...

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    83
    Thanks to everyone i finally got it workin how i wanted(more or less )

    later,
    Iceman

    (till my next stupid question anyway )

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