Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do i add remove Web browser control from a module

Posted on 2011-03-25
1
Medium Priority
?
481 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 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 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