garriew
Member
- Joined
- Sep 13, 2013
- Messages
- 13
- Programming Experience
- Beginner
I hope I can explain this clearly...
I am looping through a listbox and on each loop I need to decrease a label by 1, perform a command and then wait for a specified time before it loops to the next listbox item.
The wait time should be a random number number based on user input and will be different for each list item. The countdown will also display in a label.
I also need a command button that will stop the listbox loop. I haven't worked on this yet. Just didn't know if it mattered for the method for the above.
To do the pause/wait, I tried using a WAIT class I found but it paused the entire program so the countdown wouldn't work nor a stop button. I did get a countdown working in a timer but I couldn't get the listbox loop synced with it. The listbox just loops pretty quick.
Here is my code to generate the random number to wait & countdown.
This sets the loop label (how many time to loop) of the listbox value and loops the listbox
This is my timer1 code
I am looping through a listbox and on each loop I need to decrease a label by 1, perform a command and then wait for a specified time before it loops to the next listbox item.
The wait time should be a random number number based on user input and will be different for each list item. The countdown will also display in a label.
I also need a command button that will stop the listbox loop. I haven't worked on this yet. Just didn't know if it mattered for the method for the above.
To do the pause/wait, I tried using a WAIT class I found but it paused the entire program so the countdown wouldn't work nor a stop button. I did get a countdown working in a timer but I couldn't get the listbox loop synced with it. The listbox just loops pretty quick.
Here is my code to generate the random number to wait & countdown.
VB.NET:
'time to delay
Dim seconds As String() = TextBox1.Text.Split("-")
Dim snum1 As Integer = seconds(0)
Dim snum2 As Integer = seconds(seconds.Length - 1)
Dim RandomClass2 As New Random()
Dim RandomNumber2 As Integer If snum2 < snum1 Then
snum2 = snum1
End If
RandomNumber2 = RandomClass2.Next(snum1, snum2)
timeLeft = RandomNumber2 'this is used in my timer to count down
This sets the loop label (how many time to loop) of the listbox value and loops the listbox
VB.NET:
Label4.Text = ListBox1.Items.Count
'loop each item
For i As Integer = 0 To ListBox1.Items.Count - 1
Timer1.Enabled = True
Label5.Text = (ListBox1.Items(i))
Label4.Text = Label4.Text - 1
Next
VB.NET:
'get time to wait
Label7.Text = timeLeft & " seconds"
If timeLeft > 0 Then
timeLeft -= 1
Label7.Text = timeLeft & " seconds"
Else
Timer1.Stop()
Label7.Text = "---"
End If