VB 2005 Hi-Low Game

Hi-Low Guessing game, Total of 6 guesses, Input Boxes informing user i

Page 1 of 1

3 Replies - 3654 Views - Last Post: 23 October 2008 - 08:07 PM Rate Topic: -----

#1 chrismblinn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-October 08

VB 2005 Hi-Low Game

Posted 22 October 2008 - 09:23 PM

'Something is wrong with my Yes or No prompt, I believe.
'Can someone pinpoint my error(s)
'and lead me in the right direction please.

Public Class Form1
    Dim YNanswer As String = ("YesorNo")
    Dim Answer As Integer 'Random Number chosen by Computer
    Dim RandomNum As New Random 'Create An Instance for getting Random Numbers
    Dim Guess As Integer 'The User's guess for the answer
    Dim GuessCount As Integer 'Holds number of guesses the user has made.
    Dim I As Integer ' Counter for number of guesses in the For Loop
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Answer = RandomNum.Next(1, 101)
        I = 0
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        If I > 6 Then InputBox("Sorry, Game Over!")
        Do While YNanswer = (InputBox("Do You Want To Play"))
            If YNanswer = "Yes" Then
                InputBox("Please Enter A Number")
                Guess = CInt(InputBox("Please Enter A Number"))
                ListBox1.Items.Add(Guess)
                If CInt(Guess) > CInt(Answer) Then InputBox("Lower!")
                I = I + 1
                If CInt(Guess) < CInt(Answer) Then InputBox("Higher!")
                I = I + 1
                If CInt(Guess) = CInt(Answer) Then InputBox("Congratulations! You Got It!")
            End If

            If YNanswer = "No" Then
                InputBox("Are You Sure?")
                If InputBox("Are You Sure?") = "Yes" Then InputBox("Okay, Your Loss...")
            End If
        Loop
    End Sub
End Class



Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: VB 2005 Hi-Low Game

#2 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: VB 2005 Hi-Low Game

Posted 22 October 2008 - 09:55 PM

one thing its vb.net

ok! why should you use lot of inputbox instead of try the msgbox and more over this is the problem too, that's why you never enter the loop
ok try this
ublic Class Form1
    Dim YNanswer As DialogResult
    Dim Answer As Integer 'Random Number chosen by Computer
    Dim RandomNum As New Random 'Create An Instance for getting Random Numbers
    Dim Guess As Integer 'The User's guess for the answer
    Dim GuessCount As Integer 'Holds number of guesses the user has made.
    Dim I As Integer ' Counter for number of guesses in the For Loop
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Answer = RandomNum.Next(1, 101)
        I = 0
    End Sub

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

        Do
            If I > 6 Then
                MsgBox("Sorry, Game Over!")
                Exit Sub
            End If

            If YNanswer = DialogResult.Yes Then
                'InputBox("Please Enter A Number")
                Guess = CInt(InputBox("Please Enter A Number"))
                ListBox1.Items.Add(Guess)
                If CInt(Guess) > CInt(Answer) Then MsgBox("Lower!")
                If CInt(Guess) < CInt(Answer) Then MsgBox("Higher!")
                If CInt(Guess) = CInt(Answer) Then
                    MsgBox("Congratulations! You Got It!")
                    Exit Sub
                End If
                I = I + 1
            End If
            YNanswer = (MsgBox("Do You Want To Play", MsgBoxStyle.YesNo))
            If YNanswer = Windows.Forms.DialogResult.No Then
                If DialogResult.Yes = MsgBox("Are You Sure to Quite The game", MsgBoxStyle.YesNo) Then
                    Exit Sub
                End If
            End If
        Loop While YNanswer = DialogResult.Yes

    End Sub
End Class



some logic is missing instead of getting input from textbox get it from the button
(i.e) Dialog Result

This post has been edited by thava: 22 October 2008 - 09:56 PM

Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: VB 2005 Hi-Low Game

Posted 22 October 2008 - 10:15 PM

Moved to VB.NET :)
Was This Post Helpful? 0
  • +
  • -

#4 chrismblinn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-October 08

Re: VB 2005 Hi-Low Game

Posted 23 October 2008 - 08:07 PM

Public Class Form1
	Dim YNanswer As DialogResult 'The User's choice to play the game.
	Dim Answer As Integer 'Random Number chosen by Computer.
	Dim RandomNum As New Random 'Create An Instance for getting Random Numbers.
	Dim Guess As Integer 'The User's guess for the answer.
	Dim GuessCount As Integer 'Holds number of guesses the user has made.  
	Dim I As Integer ' Counter for number of guesses in the For Loop.
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		Answer = RandomNum.Next(1, 101)
		I = 0
	End Sub
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		Do
			If I = 6 Then
				MsgBox("Game Over!")

			End If
			If I > 6 Then Answer = RandomNum.Next(1, 101)

			If YNanswer = DialogResult.Yes Then
				'InputBox("Please Enter A Number")  
				Guess = CInt(InputBox("Please Enter A Number"))
				ListBox1.Items.Add(Guess)
				If CInt(Guess) > CInt(Answer) Then MsgBox("Lower!")
				If CInt(Guess) < CInt(Answer) Then MsgBox("Higher!")
				If CInt(Guess) = CInt(Answer) Then
					MsgBox("Congratulations! You Got It!")
					Exit Sub
				End If
				I = I + 1
				GuessCount = GuessCount + 1
			End If

			YNanswer = (MsgBox("Do You Want To Play", MsgBoxStyle.YesNo))
			If YNanswer = Windows.Forms.DialogResult.No Then
				If DialogResult.Yes = MsgBox("Are You Sure You Want To Quit The Game?", MsgBoxStyle.YesNo) Then
					Exit Sub
				End If
			End If


		Loop While YNanswer = DialogResult.Yes


	End Sub
End Class



Thank You for your help! There is one other issue I am having. Once the user has completed their 6 guesses or when the user has successfully chosen the random number, I need to prompt the user to play again; by play again, I mean to pick another random number and reset the 'I' count.

Also, I tried moving the the dialog box which asks "Do You Want To Play?" outside the loop so that the user is only prompted to answer the dialog at the beginning of the program and not after every guess.

Thanks guys!

=]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1