VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code creates a random number which the player has to guess. When you guess the number it says

by Simon Springall & Clayton D'Souza ()
Category: Games
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Wed 13th June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code creates a random number which the player has to guess. When you guess the number it says "Congratulations" and asks you your name

Rate This code creates a random number which the player has to guess. When you guess the number it says



Private Sub Command1_Click()
Dim Rnum As Integer
Dim Count As Integer
Dim Usernum As Integer
Rnum = Int(Rnd * 100)
Count = 0
a = MsgBox("I am thinking of a number....")
Do While (Rnum <> Usernum)
Usernum = InputBox("what number am I thinking of?")
    If (Usernum > Rnum) Then
    b = MsgBox("Your guess is too high, try again")
        End If
    If (Usernum < Rnum) Then
    c = MsgBox("Your guess is too low, try again")
        End If
    Count = Count + 1
Loop
d = MsgBox("Congratulations")
nam = InputBox("Oh yeah, what's your name?")
e = MsgBox("Well done " & (nam) & " you guessed the number in only " & (Count) & " tries")
If (Count > 10) Then
t = MsgBox("Sorry, You took too many guesses, please try again!")
End If
f = FreeFile
curdirt = CurDir()
Open curdirt & "Highscores.bob" For Append As #f
Write #f, nam & " : " & Count & " turns"
Close #f
Open curdirt & "Highscores.bob" For Input As #f
Do While (EOF(f) = False)
i = 1
Input #f, scores(i)
lstscores.AddItem scores(f)
i = i + 1
Loop
Close #f
Timer1.Enabled = True
Timer1.Interval = 200
End Sub

Private Sub Timer1_Timer()
r = Rnd * 255
g = Rnd * 255
b = Rnd * 255
Guessit.BackColor = RGB(r, g, b)
lstscores.BackColor = RGB(g, b, r)
End Sub


Download this snippet    Add to My Saved Code

This code creates a random number which the player has to guess. When you guess the number it says Comments

No comments have been posted about This code creates a random number which the player has to guess. When you guess the number it says . Why not be the first to post a comment about This code creates a random number which the player has to guess. When you guess the number it says .

Post your comment

Subject:
Message:
0/1000 characters