Solved

Webbrowser and find ...

Posted on 2002-03-20
8
207 Views
Last Modified: 2010-05-02
Hi!

I have a embedded Webbrowser and it's showing a HTML file. I have textbox and a OK Button in top of the HTML form. If i press the OK Button it should search for the text (which is in the textbox) and go to this "line". Is this possible?

Falke
0
Comment
Question by:Falke
  • 6
  • 2
8 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
yes, it is possible.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
Comment Utility
if you don't want to spend a penny:

Well you need to set references to microsoft html object library.
I have added one textbox to type text to serach and a command button to do the search. Webbrowser control's
name is wb1.


Option Explicit

Private Sub Command1_Click()
Dim ieDoc As HTMLDocument
   Set ieDoc = wb1.Document
   With ieDoc
       Dim TxtRng As IHTMLTxtRange
       Set TxtRng = .body.createTextRange
       If TxtRng.findText(Text1.Text) = True Then
           TxtRng.Select
           TxtRng.ScrollIntoView True
       Else
           MsgBox "Text not found", vbInformation, App.EXEName
       End If
   End With
End Sub

Private Sub Form_Load()
wb1.navigate "www.experts-exchange.com"
End Sub


Private Sub wb1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is wb1.Object) Then
   Command1.Enabled = True
Else
   Command1.Enabled = False
End If
End Sub

Hope it helps
0
 
LVL 6

Expert Comment

by:anthony_glenwright
Comment Utility
Here's one that is a bit of an upgrade on the one Ritchie posted (although I would guess that they are based on the same original sample)  -  :-)

This for if you want the full functionality (i.e. up/down, match case and full word only).

It needs:
-  A text box called txtFindTerm
-  A command button called cmdFind
-  two option buttons, optDown - "search down" and optUp - "search up" (in a frame)
-  Two check boxes, chkWholeWord - "Search whole word only" and chkCase - "Match case".

And there is a public variable called wbrDocument that is set to the document property of your webbrowser.

<general declarations>
Public wbrDocument As MSHTML.HTMLDocument
Private rngTextRange As IHTMLTxtRange

Private Sub cmdFind_Click()
  Dim intFlags As Integer
  Dim lngDirection As Long
 
  If Len(txtFindTerm.Text) > 0 Then
    If rngTextRange Is Nothing Then
      Set rngTextRange = wbrDocument.body.createTextRange
    End If
   
    With rngTextRange
      intFlags = 0
      If chkWholeWord.Value = vbChecked Then
        intFlags = intFlags + 2
      End If
      If chkCase.Value = vbChecked Then
        intFlags = intFlags + 4
      End If
     
      If optDown.Value = True Then
        lngDirection = 65535
        .moveStart "character", 1
        .moveEnd "character", 1
      Else
        lngDirection = -65535
        .moveStart "character", -1
        .moveEnd "character", -1
      End If
         
     
      If .FindText(txtFindTerm.Text, lngDirection, intFlags) = True Then
        .Select
        .scrollIntoView True
      Else
        MsgBox "Finished searching this page.", vbExclamation
      End If
     
    End With
  End If
 
End Sub
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Anthony, to tell you the true, i figured it by myself.
0
 
LVL 6

Expert Comment

by:anthony_glenwright
Comment Utility
Must be a case of covergent evolution :-)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
When i posted code, sure is mine otherwise post the link or at least, a mention to real author.
Sometimes, there are few ways to get things to work.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Thanks for "A" grade!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now