vb.net Timer with index

Hello there,
how can I have a timer with index?

something like timer(1).enabled = true
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:

You can create a array of timer's something like the following.

Dim t1 As New System.Windows.Forms.Timer
Dim t2 As New System.Windows.Forms.Timer

Dim timers(1) As System.Windows.Forms.Timer
timers(0) = t1
timers(1) = t2

timers(1).Enabled = True

Open in new window

XK8ERAuthor Commented:
I was thinking maybe something like this?
but how would I call the timer with index from (Handles allTime.Tick)

Private Structure myTimers
     Dim allTime As Timer
End Structure

Dim superTimer() As myTimers

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      For Index = 1 To 101
             ReDim superTimer(Index)
      Next Index

End Sub

Open in new window

Mike TomlinsonMiddle School Assistant TeacherCommented:
You can do something like this:
Public Class Form1

    Private AllTimers As New List(Of Timer)

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        For i As Integer = 1 To 10
            Dim tmr As New Timer
            tmr.Interval = 1000
            AddHandler tmr.Tick, AddressOf tmr_Tick

            ' ... "tmr" has NOT been started at this pont! ...

    End Sub

    Private Sub tmr_Tick(sender As Object, e As System.EventArgs)
        Dim tmr As Timer = DirectCast(sender, Timer)
        ' ... do something with "tmr" ...
    End Sub

End Class

Open in new window

*But why do you need so many timers?...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Mike TomlinsonMiddle School Assistant TeacherCommented:
**The first Timer in "AllTimers" is at Index 0 (Zero).
XK8ERAuthor Commented:
' ... "tmr" has NOT been started at this pont! ...

how can I enable lets say Timer(5) from a button ?
Mike TomlinsonMiddle School Assistant TeacherCommented:

And just another way to implement the array, along with some access to the timers:
Dim i As Integer
Dim Timers As ArrayList = New ArrayList()

For i = 0 To 100

      Timers.Add(New Timer)
      Timers(i).Interval = i + 1


Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.