Link to home
Start Free TrialLog in
Avatar of flosoft
flosoft

asked on

Searching a RTB Control Question / Performance

Hi,
I need to search for a particular list of words in a rich text control. I can do this no problem, but what I want is to show some visual feedback to my users, I have accomplished this partially with the code below.

Private Sub CheckBadWords()
On Error Resume Next
mCancel = False
Dim z As Long
Dim a() As String
Dim lngResult2 As Long
Dim i As Integer
Dim lngresult As Long
Dim lngPos As Long
Dim NumWords As Integer
pbar.Value = 0
pBar2.Value = 0
pBar2.Visible = True
Label4.Visible = True
Label3.Visible = True
btnRecheck.Visible = True
btnRecheck.Caption = "Cancel"
pbar.Visible = True
pbar.Max = frmAdmin.lstBadWords.ListCount - 1
rtfSource.MousePointer = vbHourglass
frmAdmin.lstBadWords.ListIndex = 0

If Inet1.StillExecuting = True Then
DoEvents
Else
'found = 0
oSourceStr = Inet1.OpenURL(frmAdmin.QuickBrowse.LocationURL)
rtfSource.Text = oSourceStr
a() = Split(oSourceStr, " ")
NumWords = UBound(a)
pBar2.Max = NumWords
For i = 0 To frmAdmin.lstBadWords.ListCount - 1
Me.Caption = "Checking for Word " & frmAdmin.lstBadWords.Text


For z = 0 To UBound(a)
        If a(z) = "" Then
        a(z) = 1
        End If
        'lngresult = rtfSource.Find(frmAdmin.lstBadWords.Text, lngPos, , 0)
        lngResult2 = rtfSource.Find(a(z), lngPos, , 0)
        lngPos = rtfSource.SelStart + rtfSource.SelLength
If mCancel = True Then
MsgBox "Check Cancelled", vbInformation, "Bad Word Check"
cmdOk.Enabled = True
pbar.Visible = False
pBar2.Visible = False
Label4.Visible = False
Label3.Visible = False
rtfSource.MousePointer = vbNormal
Exit Sub
End If
pBar2.Value = z
Pause 0
Next z
lngresult = rtfSource.Find(frmAdmin.lstBadWords.Text, 0, , 0)
frmAdmin.lstBadWords.ListIndex = i

If lngresult <> -1 Then
rtfSource.SelColor = vbBlue
rtfSource.SelBold = True
rtfSource.SelFontSize = 12
rtfSource.SetFocus
Me.Caption = "Check Complete - Bad Word Found"
MsgBox "Bad Words found on this site", vbInformation, "Bad Word Check"
rtfSource.MousePointer = vbNormal
pbar.Visible = False
pBar2.Visible = False
Label4.Visible = False
Label3.Visible = False
btnRecheck.Visible = True
btnRecheck.Caption = "ReCheck"
cmdOk.Enabled = True
Exit Sub
End If
'Pause Combo1.Text
pbar.Value = i
lngPos = 0
Next i

Me.Caption = "Check Complete"
MsgBox "This site has passed the bad words check!" & vbCrLf _
& "Words Checked: " & NumWords, vbInformation, "Bad words check"
rtfSource.MousePointer = vbNormal
pbar.Visible = False
pBar2.Visible = False
Label4.Visible = False
Label3.Visible = False
btnRecheck.Visible = True
btnRecheck.Caption = "ReCheck"
cmdOk.Enabled = True
End If
Screen.MousePointer = vbNormal
End Sub

pbar1 and pbar2 are progress bars 1 indicating total progress, the other the current word being looked for's progress. This all seems to work ok on smaller sites, however larger ones go slow, or the rtf jumps to the end and what I want is the current word to blaze by and the total to go however fast it needs to, I have tried this in reverse with the loop backwords( each word get checked by the bad words list instead) To make a long story short, I want to have each word highlighted as it goes through and the 2 progress bars to update so the user had some idea that the search is taking place. and to have all this happen in a consistent and stable manner. Also if someone can offer a way via the dom or whatever to read an entire webpages source via the browser control instead of using an inet control to pull the text, this would also be of great benifit.

As always any help is appreciated.

Thanks

Avatar of flosoft
flosoft

ASKER

Update to make it a little clearer.

I have loaded a websites source into a richtextbox control.

I am checking the contents against a bad word list.

The process should show the user:
1. Each word in the source is visited and highlighted, while the rtf scrolls.
2.Updates a progress bar for each word and total progess as it is going alond.
2a. This could be a check of Word Against source as above, or Source against word.
3. If a badword if found, it should highlight and bold the bad word.

The code posted does this (Word against source and loops for each word, but may seem confusing as I did not comment this. and it seems to be a slower way than what is probably possible.

I think this may clear up the question a little bit better.

Thanks again.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of flosoft

ASKER

Hi,
I already had done something just like that what I was shooting for was visiting (highlighting) every word in the rtb as the search went along. This would show a user that each word was getting visited, I know the way presented is quicker, but it provided less graphical interaction. this is why I split the source into an array, using the find method to visit each word has to part of why it is slow, there has to be a better way to highlight each word than that, but I am at a loss at the moment on that one.

If you run my code, although slower, you will see each word getting highlighted against the list, and 1 progess bar updating per word in the rtf (current progress) and the second updating per word in the list (total progress). I would like a better faster way to have a simular situation.

I do thank you for your input and look forward to any more suggestion.

I am also still trying to pull the full source out of the Browser control rather than using an inet control causing 2 downloads per url to occur, if anyone knows how to do this, that would also be greatly appreciated.

Thanks again.
Flo
Avatar of flosoft

ASKER

I guess it will be fine to use the way I was.

A note of interest, instead of using:
rtfWholeWord as a flag, use 0. Less bad words will get buy.

I am still needing a way to pull the full source of a web browser control instead of having to use an inet or other means to load a textbox.

I have experimented with using the MSHTML and MSDHTML .dll but can only seem to pull inner / outer text or inner / outer html, but not in the correct layout.

flo