Random Number guessing game in Visual Basic .Net

Random Number guessing game in Visual Basic .Net
  • Version
  • Download 246
  • File Size 63.49 KB
  • Create Date May 7, 2016

Random Number guessing game in Visual Basic .Net

This vb.net guessing game will show to us how the random function works. The user will input a number from 1 to 10, the program will then matched that number to the randomly generated number, a message box will display if you’ve guessed the number or not.

Open the project solution (.sln) in visual studio 2010/2012 or open directly the project file (.csproj)

Source code:

Public Class Form1

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

        If TextBox1.Text = "" Then
            MessageBox.Show("Please enter a number")
        Else
            Dim randNum As New Random
            Label2.Text = randNum.Next(1, 10)

            If TextBox1.Text = Label2.Text Then
                MessageBox.Show("Correct")
                TextBox1.Clear()
                Label2.Text = ""
            Else
                MessageBox.Show("Incorrect")
                TextBox1.Clear()
                Label2.Text = ""
            End If


        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.