Solved

How do i add remove Web browser control from a module

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Consuming WCF Web Service in ASP.NET 7 45
Macintosh automation 2 282
AVI wait icons for CAnimateCtrl in Visual Studio 2008 MFC 1 121
please insert disk adobe master collection6 9 597
This tutorial will show you how to add an attribute to an XML (http://en.wikipedia.org/wiki/XML) stream returned from a Windows Communication Foundation (http://en.wikipedia.org/wiki/Windows_Communication_Foundation) (WCF) Web Service.  Some knowled…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

16 Experts available now in Live!

Get 1:1 Help Now