Any of the Words
Link to us
Random number generator
VB 2005, VB 2008
Grabs a random number between two designated, or user input designated numbers. VB.NET
In the instance i have used this, Low is a variable set by the program, not the user. High is based on user input. To allow the user to choose also the low number, just edit and follow the basis for High. HighNum is a Textbox Number is a label, in the program i started with this label hidden until the number is generated. Get_random is the number generated itself. How it works speaks for itself.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Low As Integer = 1 Dim High As Integer High = HighNum.Text Get_Random(Low, High) Number.Visible = True Beep() End Sub Sub Get_Random(ByVal Low As Integer, ByVal High As Integer) Number.Text = Math.Floor((High - Low + 1) * Rnd() + Low) End Sub
© 2021 A1VBCode. All rights reserved.