-1

I am trying to code a program that does the following things:

1) Opens list of URLs (done)

2) Add to listbox (done)

3) Select first 3 items from the textbox

4) Webbrowser1, Webbrowser 2 and Webbrowser 3 navigate to the URLs selected from the listbox

5) Deletes part of the URL and adds the remaining text to Listbox2, one item at a time.

6) Removes selected items on Listbox1 and start process again.

Here's my code so far:

    Imports System.IO

Public Class Form1

Dim em As String = "@facebook.com"

Dim url As String = "https://facebook.com/profile.php?id="


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListBox1.Text = ""

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Using FD As New OpenFileDialog()
            FD.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            If FD.ShowDialog = Windows.Forms.DialogResult.OK Then
                ListBox1.Items.Clear()
                ListBox1.Items.AddRange(IO.File.ReadAllLines(FD.FileName))
            End If
        End Using
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        BackgroundWorker1.RunWorkerAsync()

    End Sub

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Me.ListBox1.SetSelected(1, True)
        Me.ListBox1.SetSelected(2, True)
        Me.ListBox1.SetSelected(3, True)

        WebBrowser1.Navigate(url + ListBox1.SelectedItems(1).ToString())
        WebBrowser2.Navigate(url + ListBox1.SelectedItems(2).ToString())
        WebBrowser3.Navigate(url + ListBox1.SelectedItems(3).ToString())



    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        ListBox2.Items.Add(WebBrowser1.Url.ToString + em)

    End Sub

    Private Sub WebBrowser2_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser2.DocumentCompleted
        ListBox2.Items.Add(WebBrowser2.Url.ToString + em)
    End Sub

    Private Sub WebBrowser3_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser3.DocumentCompleted
        ListBox2.Items.Add(WebBrowser3.Url.ToString + em)
        System.Threading.Thread.Sleep("1000")
        ListBox1.SelectedItems.Remove(1)
        ListBox1.SelectedItems.Remove(2)
        ListBox1.SelectedItems.Remove(3)
        System.Threading.Thread.Sleep("1000")
        BackgroundWorker1.RunWorkerAsync()

    End Sub
End Class

That's the easiest way I could think of doing it (I have no experience with loops). Any help is appreciated because I haven't used VB.Net in a few years.

Hoh
  • 1,196
  • 1
  • 12
  • 30
Bryan99
  • 19
  • 1
  • 5
  • Sorry, but I can't understand what is your question. – Steve Aug 15 '14 at 20:32
  • Hey, sorry but I forgot to mention it. http://i.imgur.com/40BGwPk.png – Bryan99 Aug 15 '14 at 20:36
  • possible duplicate of [Crossthread operation not valid... - VB.NET](http://stackoverflow.com/questions/2240702/crossthread-operation-not-valid-vb-net) Ignore any answers in that post that has `CheckForIllegalCrossThreadCalls = False` because that's bad advice. – LarsTech Aug 15 '14 at 21:20

1 Answers1

0

BackgroundWorkers cannot modify any "physical" objects. Like those things you can see in the form. BackgroundWorkers can only modify abstract objects, such as variables.

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75