user3478700
user3478700

Reputation: 5

How can i fix this with ListBox issue?

this is my code:

Private Sub StartToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As     System.EventArgs) Handles StartToolStripMenuItem.Click
    Video1.Start()
    Video1.Interval = 4000
    ToolStripStatusLabel2.Text = "Browsing"
End Sub

Private Sub Video1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Video1.Tick
    ToolStripStatusLabel4.Text += 1
    ListBox1.SelectedIndex = rnd.Next(0, ListBox1.Items.Count - 1)
    WebBrowser1.Navigate(ListBox1.SelectedItem)
End Sub

Problem is lets say the timer interval is set to 4 secods (4000). i want my application to navigate to each item in my ListBox in order: website1, website 2, website3, ect. But instead its doing this: website 5, website2, website 8, website 1. Its navigating to randome website.

Upvotes: 0

Views: 74

Answers (1)

gareththegeek
gareththegeek

Reputation: 2418

The reason it's random appears to be because you are calling the random number generator and selecting that item from the list box:

rnd.Next(0, ListBox1.Items.Count - 1)

Instead you should allocate a variable which stores which index you are currently on. Increment this each time the timer ticks.

Private currentIndex As Integer = 0

Private Sub Video1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)     Handles Video1.Tick
    ToolStripStatusLabel4.Text += 1
    currentIndex += 1
    ListBox1.SelectedIndex = currentIndex
    WebBrowser1.Navigate(ListBox1.SelectedItem)
End Sub

Upvotes: 1

Related Questions