Solved

How do i add remove Web browser control from a module

Posted on 2011-03-25
1
472 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

10 Experts available now in Live!

Get 1:1 Help Now