2 Replies - 610 Views - Last Post: 17 February 2013 - 11:29 AM Rate Topic: -----

#1 jsheehan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-February 13

error in guessing game code

Posted 17 February 2013 - 10:54 AM

i am working on a guesing game, however the only message box that appears in you win. I cannot figure out what the problem is. Help Please!


Private Sub btnGuess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuess.Click

        Dim intCount As Integer  'keeps running total of loops (increments)
        Dim txtBoxGuess As Integer 'actual number the user inputs as guesses
        Dim intAnswer As Integer 'random number assigned to be guessed
        Dim intMin As Integer = 1 'low number of range
        Dim intMax As Integer = 25 'high number of range
        

        If txtBoxGuess = intAnswer Then
            MessageBox.Show("You Win")
            End

        ElseIf txtBoxGuess > intAnswer Then
            MessageBox.Show("Too High", "Try Again...")
            End

        ElseIf txtBoxGuess < intAnswer Then
            MessageBox.Show("Too Low", "Try Again...")

        End If




    End Sub





Is This A Good Question/Topic? 0
  • +

Replies To: error in guessing game code

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5675
  • View blog
  • Posts: 12,192
  • Joined: 02-June 10

Re: error in guessing game code

Posted 17 February 2013 - 11:19 AM

There are more than 500,000 users on the DIC. Can you imagine if they all titled threads as "Error" ? Please use meaningful titles so the people with the most knowledge in your area are drawn to your question. This also helps people later using search engines to find the help they need.

We can't fix your homework for you. You get graded on your abilities, now ours. But we can point you to some tutorials that will show you how to use breakpoints and do basic debugging, which is what you need to do here. You need to follow the execution line by line during run-time and double check your logic and the true values of variables.


tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Jan 2013
Spoiler




I will point out that textboxes hold TEXT not NUMBERS.
So you can't do mathematic comparisons.
Textbox.text contains "5" not 5. Notice the quotes since it is a piece of text that happens to contain a number. It is not however an actual number: IE It is a string not an int or a double or a float

Basically you are trying to do this:
if "yogibear" > 10 then

Was This Post Helpful? 0
  • +
  • -

#3 FerretHolmes  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 167
  • Joined: 12-November 12

Re: error in guessing game code

Posted 17 February 2013 - 11:29 AM

Hint:
Convert.toInt32()
/* or */
Convert.toString()


This post has been edited by FerretHolmes: 17 February 2013 - 11:30 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1