• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

listbox emails

hello,
I have a listbox with 10 websites in it.
I would like to create a button that
visits the 10 websites every 5 seconds
how would I do that?
0
aplelois
Asked:
aplelois
  • 6
  • 5
1 Solution
 
Fahad MukhtarDistinguished EngineerCommented:
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each url As Object In ListBox1.Items
            System.Threading.Thread.Sleep(5000)
            System.Diagnostics.Process.Start(url.ToString())
        Next
    End Sub
0
 
bruintjeCommented:
Hello aplelois,

another option is using a timer
the button sets the interval and enables the timer
myInt is a property of the form
webbrowser1 is a webbrowser on the form

    Private myInt As Integer = 0

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        myInt = 0
        Timer1.Interval = 5000
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If myInt <= ListBox1.Items.Count - 1 Then
            ListBox1.SelectedIndex = myInt
            WebBrowser1.Navigate(ListBox1.Items(myInt).ToString())
            myInt = myInt + 1
        End If
    End Sub

hope this helps a bit
bruintje
0
 
apleloisAuthor Commented:
bruintje, your code is working awsome.
but maybe not 5 seconds cause If the person is on dial up he wont be able to load all pages
in 5 seconds, so If I put it to 30 secs the ppl who has DSL will have to wait? so what shall I do?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
apleloisAuthor Commented:
I want the ppl to be able to see the page for 5 seconds after the page has loaded!
0
 
bruintjeCommented:
the webbrowser has an event for this it signals that the page is loaded and you can set the timer there have to look it up
0
 
bruintjeCommented:
didn't try this yet but how about disabling the timer when the browser starts navigating and enabling when it is done and the user can look at the page for 5 seconds

    Private myInt As Integer = 0

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If myInt <= ListBox1.Items.Count - 1 Then
            Timer1.Enabled = False
            ListBox1.SelectedIndex = myInt
            WebBrowser1.Navigate(ListBox1.Items(myInt).ToString())
            myInt = myInt + 1
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        myInt = 0
        Timer1.Interval = 5000
        Timer1.Enabled = True
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Timer1.Enabled = True
    End Sub
0
 
apleloisAuthor Commented:
Error      1      'Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)' has multiple definitions with identical signatures.
0
 
apleloisAuthor Commented:
I have on frmMain_Load navegate --> home
and as soon as home is done loading it stars going to the sites!
0
 
bruintjeCommented:
ok i had one webbrowser on my form called webbrowser1

so you need to create your own by doubleclicking on the webbrowser you should get your own handler and can paste the line

Timer1.Enabled = True

in there
0
 
bruintjeCommented:
ok now i see your second comment

then make it something like

Private myInt As Integer = 0

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If myInt <= ListBox1.Items.Count - 1 Then
            Timer1.Enabled = False
            ListBox1.SelectedIndex = myInt
            WebBrowser1.Navigate(ListBox1.Items(myInt).ToString())
            myInt = myInt + 1
        Else
            myInt = 0
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        myInt = 0
        Timer1.Interval = 5000
        Timer1.Enabled = True
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        if myInt > 0 then Timer1.Enabled = True
    End Sub
0
 
apleloisAuthor Commented:
nice, thats what im looking for but it keeps going from the last site to the first one!
0
 
apleloisAuthor Commented:
is there a way to stop the loop when It gets a the last site?
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now