Results 1 to 2 of 2

Thread: Faster search for RTB

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    Tennessee
    Posts
    378

    Unhappy Faster search for RTB

    Hello, Anybody know of a faster way to search a rich text box that contains the whole Bible? This code takes forever. If I take just the old testiment by its self or just the new, it is fast enough, but the whole Bible is too slow. HELP!


    VB Code:

    Private Sub Command1_Click()
    Dim LOOPNUM As Integer
    Dim strtext As String
    Dim intIdx As Long
    Dim RESPONSE As String
    Dim CountLeft As Integer

    strtext = rtfText7.Text
    If txtFind2.Text = "" Then
    COUNTED = 0
    Exit Sub
    End If

    COUNTED = COUNTED + 1
    On Error GoTo FIXIT

    CountLeft = WordCount(strtext, txtFind2.Text) - COUNTED

    LOOPNUM = LOOPNUM + 1
    FoundLabel.Caption = " " & "Hit #" & COUNTED & " of " & WordCount(strtext, txtFind2.Text) & ", there are " & CountLeft & " Left"

    If LOOPNUM = 2 Then
    FoundLabel.Caption = " " & "Hit #" & COUNTED - 1 & " of " & WordCount(strtext, txtFind2.Text)

    COUNTED = 0
    Exit Sub
    End If

    POS = WholeBible.rtfText7.SelStart
    POS = InStr(POS + 1, WholeBible.rtfText7.Text, txtFind2.Text)

    If POS = 0 Then

    RESPONSE = MsgBox("your search for ~ " & txtFind2 & " ~ ... was found a total of " & COUNTED - 1 & " time(s). ... Do you want to start from the beginning?", vbYesNo)
    COUNTED = 0
    FoundLabel.Caption = " " & "Hit #" & COUNTED & " of " & WordCount(strtext, txtFind2.Text)

    If RESPONSE = vbNo Then
    Exit Sub
    End If
    Else

    rtfText7.Find txtFind2, rtfText7.SelStart + 1, Len(rtfText7.TextRTF), rtfWholeWord

    rtfText7.SelColor = vbRed
    rtfText7.SetFocus

    End If

    WholeBible.rtfText7.SelStart = POS 'GOES TO THE TOP
    Exit Sub


    FIXIT:
    MsgBox "Try a less common word in your search."
    Exit Sub

    End Sub
    Thanks,
    GARY

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Faster search for RTB

    I can't figure out what you're trying to do with your code, have you accidently pasted two subs together?

    I should think the fastest way to search an RTB would be to use the built in Find method as it will be written in a low-level language and optimised:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Debug.Print CountWords(RichTextBox1, "hello")
    3. End Sub
    4.  
    5. Private Function CountWords(ByRef rtb As RichTextBox, ByRef sFind As String) As Long
    6.     Dim lPos As Long
    7.     Do
    8.         lPos = rtb.Find(sFind, lPos, Len(rtb.Text), rtfWholeWord)
    9.         If lPos >= 0 Then CountWords = CountWords + 1: lPos = lPos + Len(sFind)
    10.     Loop Until lPos = -1
    11. End Function

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