Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Webbrowser and find ...

Posted on 2002-03-20
8
Medium Priority
?
241 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

876 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