hey all,

i've got a new issue with a program that allows the user to enter a number and then that number is checked against a random number that the PC chooses. Here's the code:

Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click
        'show the random number
        Dim randomnum As Integer
        Dim randomGenerator As New Random

        randomnum = randomGenerator.Next(1, 51) 'give the number

        Dim userent As String

        Dim usernum As Integer
        Dim chancecount As Integer = 0

        Dim isConverted As Boolean


        userent = Me.xEnterTextBox.Text
        'go as long as they enter a number
        Do While userent <> String.Empty
            'convert the sales number
            isConverted = Integer.TryParse(userent, usernum)

            If isConverted And usernum < randomnum Then
                chancecount = chancecount + 1
                Me.xAnswerLabel.Text = "Oops, too low. Go a little higher"

            ElseIf usernum > randomnum Then
                chancecount = chancecount + 1
                Me.xAnswerLabel.Text = "Whoa! Whoa! You're guessing a little too high now."
            End If

        Loop

        If usernum = randomnum Then
            Me.xAnswerLabel.Text = "Congratulations, you have selected the correct number which is, " + Convert.ToString(usernum)
        Else

        End If


    End Sub

I know i'm on the brink but what exactly am I missing? should i make the random constant or something?

okay,

forget the above. I got it working with this except:

Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click

        'show the random number        
        Dim randomnum As Integer
        Dim randomGenerator As New Random

        randomnum = randomGenerator.Next(1, 51) 'give the number

        Dim usernum As Integer
        Dim chancecount As Integer = 0

        Integer.TryParse(Me.xEnterTextBox.Text, usernum)


        If usernum < randomnum Then
            chancecount = chancecount + 1
            Me.xAnswerLabel.Text = "Oops, too low. Go a little higher"

        ElseIf usernum > randomnum Then
            chancecount = chancecount + 1
            Me.xAnswerLabel.Text = "Whoa! Whoa! You're guessing a little too high now."

        ElseIf usernum = randomnum Then
            Me.xAnswerLabel.Text = "Congratulations, you have selected the correct number which is, " + Convert.ToString(usernum)

        End If


    End Sub

the only thing now is that the pc won't keep the number...should i create the random variable when the program loads?

okay...just solved this myself...

lol, this forum is very therapeutic haha.

Option Explicit On
Option Strict On

Public Class MainForm
    'show the random number
    Dim randomGenerator As New Random
    Dim randomnum As Integer = randomGenerator.Next(1, 51) 'give the number

    Private Sub xExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xExitButton.Click
        Me.Close()

    End Sub

    Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click


        Dim usernum As Integer
        Dim chancecount As Integer = 0

        Integer.TryParse(Me.xEnterTextBox.Text, usernum)


        If usernum < randomnum AndAlso chancecount <= 10 Then
            chancecount = chancecount + 1
            Me.xAnswerLabel.Text = "Oops, too low. Go a little higher"

        ElseIf usernum > randomnum AndAlso chancecount <= 10 Then
            chancecount = chancecount + 1
            Me.xAnswerLabel.Text = "Whoa! Whoa! You're guessing a little too high now."

        ElseIf usernum = randomnum Then
            Me.xAnswerLabel.Text = "Congratulations, you have selected the correct number which is, " + Convert.ToString(usernum) + "!"

        End If


    End Sub
End Class

well great, i want to answer but you have done it.

commented: you late +1
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.