Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[ SOURCE CODE ]  Guess the number game
#1
Ok vister i like to share my guess the number game code with you guys if you still need help it let me know i will make video about it.

Before you start coding my code you need..
  • Visual Studio any version you got.
When you got the "Visual Studio" open it and make new project after you make a project you will got form in from you still need i few items to the code work ok.

Items need..
  • 1 textbox
  • 1 button
  • 1 label
You done all and place however you want or like.
After that let start coding..

Now click the button and copy blow code them pest the code..
Code:
        If TextBox1.Text = "" Then
            MessageBox.Show("Please enter a number")

        Else
            Dim randNum As New Random
            Label1.Text = randNum.Next(1, 10)

            If TextBox1.Text = Label1.Text Then
                MessageBox.Show("Correct", "Your Guess Was...", MessageBoxButtons.OK, MessageBoxIcon.None)
                TextBox1.Clear()
                Label1.Text = ""
            Else
                MessageBox.Show("Incorrect", "Your Guess Was...", MessageBoxButtons.OK, MessageBoxIcon.None)
                TextBox1.Clear()
                Label1.Text = ""
            End If

        End If

After you pest all the it will look like blow code
Code:
Public Class Form1

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

        If TextBox1.Text = "" Then
            MessageBox.Show("Please enter a number")

        Else
            Dim randNum As New Random
            Label1.Text = randNum.Next(1, 10)

            If TextBox1.Text = Label1.Text Then
                MessageBox.Show("Correct", "Your Guess Was...", MessageBoxButtons.OK, MessageBoxIcon.None)
                TextBox1.Clear()
                Label1.Text = ""
            Else
                MessageBox.Show("Incorrect", "Your Guess Was...", MessageBoxButtons.OK, MessageBoxIcon.None)
                TextBox1.Clear()
                Label1.Text = ""
            End If

        End If

    End Sub
End Class


That it now you can test it work or not.
If not work let me know i will help you to work.

Enjoy....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)