VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Used in VB 6 A guessing game where you must guess a number between 1 and 100 (the computer randomly

by Patryk Jakubowski (1 Submission)
Category: Games
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 21st March 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Used in VB 6 A guessing game where you must guess a number between 1 and 100 (the computer randomly chooses a number every time.. keeps track

API Declarations


Dim compnumber As Integer
Dim usercount As Integer

You will need 3 textbox's named
txtguess
txtmessage
txtcount

A label named
lblinstruction

three command buttons named
cmdguess
cmdHoeToPlay
cmdReset

A list box named
lstguess




Rate Used in VB 6 A guessing game where you must guess a number between 1 and 100 (the computer randomly



Dim userguess As Integer
Dim compnumber As Integer
Dim usercount As Integer


Private Sub cmdGuess_Click()

userguess = txtguess.Text
If userguess > compnumber Then
    txtmessage.Text = "Lower"
    
ElseIf userguess < compnumber Then
    txtmessage.Text = "Higher"

ElseIf txtmessage.Text = "CORRECT" Then
    MsgBox "Good job.. Play again?"

End If

    lstGuess.AddItem txtguess.Text
    txtguess.Text = ""
    txtguess.SetFocus
    usercount = usercount + 1
    txtCount.Text = usercount
  
  End Sub

Private Sub cmdHowToPlay_Click()
    MsgBox "Type a number between 0 and 100 into the box labeled Type Guess Here. The program will generate a random number and will tell you if you've gone to high or to low, keep guessing until you are CORRECT! but you only have 6 guesses."
End Sub

Private Sub cmdReset_Click()
cmdGuess.Enabled = False
txtguess = ""
lstGuess.Clear
txtmessage = ""
txtCount = ""
usercount = 0
Randomize
    compnumber = (Rnd * 100)
    usercount = 0
End Sub

Private Sub Form_Load()

Randomize
    compnumber = (Rnd * 100)
    usercount = 0
End Sub




Private Sub txtCount_Change()
If txtCount.Text = "7" Then
    txtCount.Text = "6"
    MsgBox ("Game Over")
    cmdGuess.Enabled = False
    End If
End Sub


Download this snippet    Add to My Saved Code

Used in VB 6 A guessing game where you must guess a number between 1 and 100 (the computer randomly Comments

No comments have been posted about Used in VB 6 A guessing game where you must guess a number between 1 and 100 (the computer randomly. Why not be the first to post a comment about Used in VB 6 A guessing game where you must guess a number between 1 and 100 (the computer randomly.

Post your comment

Subject:
Message:
0/1000 characters