0
votes

I'm trying to make a simple auto typer in Visual Basic. I want it to take the ListBox items and output at the user's choice of interval.

The problem is I don't know how to make the Timer's Tick event send each line and restart at the top of the list and continue to loop this way.

Form Design:

enter image description here

I have not listed much code because there really isn't much to list yet.

Private Sub intervalTimer_Tick(sender As Object, e As EventArgs) Handles intervalTimer.Tick

End Sub
1
Where do you want the output?, or you just need to know how to get the first line and loop through using the timer? - Mousa Alfhaily
The TextBox with "Seconds" in it isn't a great place to read a number from. Do you want to accept inputs like "4 Seconds", "5 minutes", and "0.15 Minutes"? You'd need to also account for inputs like "4seconds", "four seconds", and "ibfcweew". Use a NumericUpDown control instead, possibly paired with a DropDown populated with "Minutes" and "Seconds". - djv
I want it to take the ListBox items and output at the user's choice of interval. output where / how? - djv
Took me awhile but I figured it out, thanks for the replies though. (The interval is purely in seconds) - Justin

1 Answers

0
votes

Here is a code, but you need to replaced the ListBox with a ListView, it is the same look, this is just for the code to work.

This code is going to take each line from the ListView and output it using MsgBox using a timer that has an interval of user's choice, just remove the message box and output the result where ever you need, and you're all good :

First define this variable in your public class :

Dim ListedItems As String

Here is when you press the set button to set the interval :

Try
    intervalTimer.Interval = intervalTextBox1.Text * 1000
Catch
    MsgBox("The interval must be in purly seconds only!")
End Try

Here is when you press the start button :

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    For Each LVI As ListViewItem In ListView1.Items
        If ListedItems = "" Then
            ListedItems = LVI.Text
        Else
            ListedItems &= vbLf & LVI.Text
        End If
    Next
    Timer1.Start()
End Sub

Here is when the timer tick event :

Private Sub intervalTimer_Tick(sender As Object, e As EventArgs) Handles intervalTimer.Tick
    intervalTimer.Stop()
    Dim SeprateLine As String
    Dim Separator As Integer
    If ListedItems.Contains(vbLf) Then
        Separator = ListedItems.IndexOf(vbLf)
        SeprateLine = ListedItems.Remove(Separator)
        ListedItems = ListedItems.Substring(Separator + 1)
    Else
        SeprateLine = ListedItems
        ListedItems = ""
    End If
    MsgBox(SeprateLine)
    If ListedItems <> "" Then
        intervalTimer.Start()
    End If
End Sub

Finally i hope that this will help you with what you need :)