Random Guessing Game in Visual Basic

Download
Download is available until [expire_date]
  • Version
  • Download 59
  • File Size 254.16 KB
  • File Count 1
  • Create Date March 2, 2016
  • Last Updated March 2, 2016

Random Guessing Game in Visual Basic

Random Guessing Game in Visual Basic

This is a simple guessing game in visual basic. The user will be ask to enter a number from 1 to 10 if the input is same as the result of the randomly selected number, then the guess is correct.

The sample code has a feature that only numeric value is allowed to enter in a textbox.

Tutorial in a pdf format and source code are included in the file.

Source code:

Private Sub Command1_Click()
If Text1.Text = "" Or Val(Text1.Text) > 10 Then
MsgBox "Please enter a number from 1 to 10"
Else
Label3.Caption = Int(Rnd * 11)
End If
End Sub
Private Sub Label3_Change()
If Val(Label3.Caption) = Val(Text1.Text) Then
MsgBox "correct"
Else
MsgBox "incorrect"
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = 46 Or KeyAscii = vbKeyBack Then
Else
   Beep
   KeyAscii = 0
End If
End Sub
, , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.