Generate Random Number in Visual Basic .Net

Download
Download is available until [expire_date]
  • Version
  • Download 90
  • File Size 104.17 KB
  • File Count 1
  • Create Date April 5, 2016
  • Last Updated April 5, 2016

Generate Random Number in Visual Basic .Net

Generate Random Number in Visual Basic .Net

This is a simple program in vb.net that will generate a random number using the Randomize function.

The program will require you to enter a minimum and maximum number, based on that the program will generate a random number between the minimum and maximum number entered by the user.

Source code:

Public Class Form1

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

        If IsNumeric(TextBox1.Text) = False Or TextBox1.Text = "" Then
            MessageBox.Show("Please enter a numeric value")
            TextBox1.Focus()
        ElseIf IsNumeric(TextBox2.Text) = False Or TextBox2.Text = "" Then
            MessageBox.Show("Please enter a numeric value")
            TextBox2.Focus()
        ElseIf Val(TextBox2.Text) < Val(TextBox1.Text) Then
            MessageBox.Show("maximum value should not be less than or equal to the minimum value")
            TextBox2.Focus()
        Else
            Dim randNum As New Random
            randNum.Next(TextBox1.Text, TextBox2.Text)

            Label3.Text = randNum.Next(TextBox1.Text, TextBox2.Text)
        End If

    End Sub
End Class
, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.