hi guys, writing a code in my first term at vb 2010, ive to create a guessing game, generate a number between 1 and 30 and let the user guess it. i must give hints along the way and record the amount of guesses made. i have the code written and working. my problem lays with changing the range. if i change the range to any other number, when i press enter it keeps givin a new random number each time.
Public Class frmMain

Public min As Integer
Public max As Integer
Public randomClass As New Random
Public num As Integer

Public X As Integer


'Dim X As Integer = Int(X * Rnd())

Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult


Private Sub frmMain_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    min = 1
    max = 30

    Randomize()
    X = randomClass.Next(min, max)
    'X = CInt(Int(30 * Rnd()))
    lblMin.Text = min.ToString
    lblMax.Text = max.ToString
    For i As Integer = min To max
        ComboBox1.Items.Add(i)
    Next
End Sub

Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ExitToolStripMenuItem.Click
    End
End Sub

Private Sub BackgroundColourToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles BackgroundColourToolStripMenuItem.Click

End Sub



Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click


    txtAttempts.Text = Val(txtAttempts.Text) + 1


    num = ComboBox1.Text
    Label2.Text = X

    If ComboBox1.SelectedIndex = X Then
        MsgBox("Congratulations!!!")
        msg = "  do you want to Exit"
        title = "MsgBox Close"

        style = MsgBoxStyle.Critical Or MsgBoxStyle.YesNoCancel
        response = MsgBox(msg, style, title)

        If response = MsgBoxResult.Yes Then 'user choose yes
            'perform some action
            MsgBox("THANK YOU FOR PLAYING THE GUESSING GAME!!")
            End
        ElseIf MsgBoxResult.No Then 'user choose no

            txtGameTotal.Text = Val(txtGameTotal.Text) + 1

            txtAverage.Text = "Your Average is " & txtAttempts.Text / txtGameTotal.Text
            MsgBox("Your Average Guess Total is " & txtAttempts.Text / txtGameTotal.Text)

            X = Int(X * Rnd())
            txtEntry.Clear()
            txtAttempts.Clear()

            Return
        ElseIf MsgBoxResult.Cancel Then  'user choose cancel
            'perform some action
            txtGameTotal.Text = Val(txtGameTotal.Text) + 1
            txtAverage.Text = "Your Average is " & txtAttempts.Text / txtGameTotal.Text
            MsgBox("Your Average Guess Total is " & txtAttempts.Text / txtGameTotal.Text)
            txtEntry.Clear()
            txtAttempts.Clear()

            Return
        End If




        X = Int(X * Rnd())

    End If
    If num < X Then
        txtEntry.Text = ("You are too low!!!")

    End If
    If num > X Then
        txtEntry.Text = ("You are too high!!!")


    End If


End Sub

Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
    MsgBox("THANK YOU FOR PLAYING THE GUESSING GAME!!")

    End
End Sub


Private Sub LightBlueToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles LightBlueToolStripMenuItem1.Click
    Me.BackColor = Color.LightBlue

End Sub

Private Sub GreenToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles GreenToolStripMenuItem1.Click
    Me.BackColor = Color.Green

End Sub

Private Sub BeigeToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles BeigeToolStripMenuItem1.Click
    Me.BackColor = Color.Beige

End Sub

Private Sub CrimsonToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles CrimsonToolStripMenuItem1.Click
    Me.BackColor = Color.Crimson

End Sub

Private Sub RangeToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles RangeToolStripMenuItem.Click
    frmRange.Show()
End Sub



Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

End Sub

Private Sub btnRandom_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRandom.Click


    'Randomize()
    'X = randomClass.Next(min, max)

    lblMin.Text = min.ToString
    lblMax.Text = max.ToString
    TextBox1.Text = X

    txtAttempts.Text = Val(txtAttempts.Text) + 1


    num = ComboBox1.Text
    Label2.Text = X

    If ComboBox1.Text = X Then
        MsgBox("Congratulations!!!")
                msg = "  do you want to Exit"
                title = "MsgBox Close"

                style = MsgBoxStyle.Critical Or MsgBoxStyle.YesNoCancel
                response = MsgBox(msg, style, title)

                If response = MsgBoxResult.Yes Then 'user choose yes
                    'perform some action
                    MsgBox("THANK YOU FOR PLAYING THE GUESSING GAME!!")
                    End
                ElseIf MsgBoxResult.No Then 'user choose no

                   txtGameTotal.Text = Val(txtGameTotal.Text) + 1

                    txtAverage.Text = "Your Average is " & txtAttempts.Text / txtGameTotal.Text
                    MsgBox("Your Average Guess Total is " & txtAttempts.Text / txtGameTotal.Text)

                    X = Int(X * Rnd())
                    txtEntry.Clear()
                    txtAttempts.Clear()

                    Return
                ElseIf MsgBoxResult.Cancel Then  'user choose cancel
                    'perform some action
                   txtGameTotal.Text = Val(txtGameTotal.Text) + 1
                   txtAverage.Text = "Your Average is " & txtAttempts.Text / txtGameTotal.Text
                   MsgBox("Your Average Guess Total is " & txtAttempts.Text / txtGameTotal.Text)
                   txtEntry.Clear()
                   txtAttempts.Clear()

        '            Return
    End If




    '        X = Int(X * Rnd())

    '    End If
    '    If num < X Then
    '        txtEntry.Text = ("You are too low!!!")

    '    End If
    '    If num > X Then
    '        txtEntry.Text = ("You are too high!!!")


    '    End If



End Sub

End Class

sorted myself

num = ComboBox1.Text
        Label2.Text = X

        If ComboBox1.SelectedIndex = X Then



    i should have had num = X.  i wanted to get the principals of the game working before i ironed out the small issues
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.