Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

Setting a Random Timer Interval in VB

$
0
0
Hi all,

I'm a beginner who's come to a road block. My goal is to make code that will beep randomly anywhere from 1 to 30 seconds apart. Here is my code so far:

Code:

Public Class Form1

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Console.Beep()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Stop()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
    End Sub
End Class

This beeps every one second. Now, I want to change the Timer Interval so that it will beep randomly between 1 and 30 seconds. Maybe later I will add options for the user to define the bounds, but for now, 1 and 30 are good numbers. I just don't know how to apply a random number to my Timer Interval. Can anyone help? Thanks in advance.

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>