Results 1 to 2 of 2

Thread: How to start a random Timer after a condition is met?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Question How to start a random Timer after a condition is met?

    First of all, is something like that even possible because I don't really know. Second, anyone got any ideas?

    I want to do smth like instead of typing
    vb Code:
    1. Timer1.Start()
    I can type
    vb Code:
    1. TimerA.Start()
    where A is a random integer declared before.

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: How to start a random Timer after a condition is met?

    If you have multiple timers you could add them to a list, then use a random number from zero to the list count to select which timer to start, try something like...

    Code:
        Private myTimers As New List(Of Timer)
        Private rand As New Random
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            ' add timers to the list
            myTimers.AddRange({Timer1, Timer2, Timer3})
        End Sub
    
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            ' get random number between zero and our timers list count
            Dim index As Integer = rand.Next(0, myTimers.Count)
            ' start the timer
            myTimers(index).Start()
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width