Generate Random Numbers - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This is a tutorial on how to generate random numbers in Visual Basic .NET

Let's say you have a button and each time the user clicks on it, it generates a randomly picked number by the computer and displays it in a textbox

The code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim number As Integer
 
        Randomize()
        ' The program will generate a number from 0 to 50
        number = Int(Rnd() * 50) + 1
 
        TextBox1.Text = number
    End Sub


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.