Solved

Webbrowser and find ...

Posted on 2002-03-20
8
213 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
ID: 6883055
yes, it is possible.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6883093
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 100 total points
ID: 6883097
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 6884822
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
 
LVL 16

Expert Comment

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

Expert Comment

by:anthony_glenwright
ID: 6887164
Must be a case of covergent evolution :-)
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6887549
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
ID: 6903364
Thanks for "A" grade!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

830 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