Solved

How do i add remove Web browser control from a module

Posted on 2011-03-25
1
479 Views
Last Modified: 2012-05-11
I order to get page data from web site i'm using this code: (get page)
this code after a few pages donut work i think maybe because i'm  not add/remove web bowser properly from my form: "frmMain".
can some one fix it?

sample URL:
http://www.b144.co.il/search.aspx?txtNamePrivate=%D7%9C%D7%99%D7%91%D7%A9%D7%99%D7%A5&txtCityPrivate=%D7%A6%D7%A4%D7%AA&txtStreetPrivate=&txtStreetNPrivate=&_private=0&_p=&_lang=HE

 
Public Function Get_Page(ByVal sURL As String) As String

        Dim sResult As String = vbNullString
        Try
            Const cTitle As String = "144 ¿¿¿"
            Dim oWeb As New WebBrowser
            With oWeb
                oWeb.Name = "WebBrowser1"
                frmMain.Controls.Add(oWeb)
                .Visible = True
                .Navigate(sURL)
                Whit4(3)
                DoEvents()
                frmMain.Refresh()
                Debug.Print(oWeb.DocumentTitle)
                sResult = .DocumentTitle
                Dim iCount As Integer = 0
                Do Until InStr(sResult, cTitle) > 0
                    Whit4(3)
                    iCount = iCount + 1
                    sResult = .DocumentTitle
                    If iCount >= 3 Then
                        If len(sResult)=0 Then
                           oWeb.Dispose()
                           frmMain.Controls.Remove(oWeb)
                            Exit Try
                        end if
                    End If
                Loop
lbl_read_data:
                Dim sr As System.IO.StreamReader = New           System.IO.StreamReader(.DocumentStream, System.Text.Encoding.UTF8)
                sResult = sr.ReadToEnd()
                sr.Close()
                oWeb.Dispose()
                frmMain.Controls.Remove(oWeb)
            End With
            GC.Collect()
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.ToString)
            'MsgBox(Err.Description & Chr(32) & Err.Number & vbCrLf & "Proc getrequestuelsource mod app actions")
        End Try
        Return sResult
        'sr = new System.IO.StreamReader(objRes.GetResponseStream(), System.Text.Encoding.GetEncoding("windows-1255"));

    End Function

Open in new window

0
Comment
Question by:rshaham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 total points
ID: 35220392
Perhaps it would work better if you added the webbrowser control to the form design time rather than runtime?

Another thought: you are trying to dispose the control prior to removing it from the control collection.  It may work better to remove it, then dispose...

frmMain.Controls.Remove(oWeb)
oWeb.Dispose()
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

628 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