by Christopher Brown (2 Submissions)
Category: Games
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 1st November 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This is a number guessing game, the last one that i submitted had a small bug in that it didn't give you a clue to what the number is.
API Declarations
Dim guess As Integer
Dim number As Integer
Dim counter As Integer
On Error GoTo Error 'If a number entered is outside the range this lets you know
Randomize
number = Int(1000 * Rnd) + 1 'This randomizes the number
counter = 0
Do
guess = InputBox("I am thinking of a number please have a guess at what it is.") 'This places you guees into the variable named guess
If guess > 1000 Or guess < 1 Then 'This is part of the error handler
GoTo Error
End If
If guess = number Then
MsgBox ("Spot on") 'If you get the number right then this displays a messagebox, and end the game.
End
Else
If guess > number Then
MsgBox ("Your guess is too high") 'This tells you that you guees maybe too high
Else
MsgBox ("Your guess is too low") 'This tells you that you guess maybe too low
End If
End If
counter = counter + 1 'This counts the number of attempts that you have made
Loop Until counter = 10 'This limits the number of guesses to 10 by placing a text box, and an exta variable you can get the form to specify how many guesses you can make.
MsgBox ("Sorry the number was ") & number 'If you have the maximum amount of guesses allowed and still get it wrong then thi message is displayed
Error:
MsgBox ("Please input a valid number between 1 and 1000 inclusive.") 'This is the error message diplayed wehnt eh erro handler is triggered
End Sub
Private Sub cmdquit_Click()
End 'This quits the game
End Sub
No comments have been posted about This is a number guessing game, the last one that i submitted had a small bug in that it didn't giv. Why not be the first to post a comment about This is a number guessing game, the last one that i submitted had a small bug in that it didn't giv.