home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / beginn1a / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-12  |  2.1 KB  |  57 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   2640
  5.    ClientLeft      =   3555
  6.    ClientTop       =   2715
  7.    ClientWidth     =   4410
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   176
  10.    ScaleMode       =   3  'Pixel
  11.    ScaleWidth      =   294
  12.    Begin VB.CommandButton Command1 
  13.       Caption         =   "Command1"
  14.       Height          =   375
  15.       Left            =   1320
  16.       TabIndex        =   0
  17.       Top             =   600
  18.       Width           =   1695
  19.    End
  20. Attribute VB_Name = "Form1"
  21. Attribute VB_GlobalNameSpace = False
  22. Attribute VB_Creatable = False
  23. Attribute VB_PredeclaredId = True
  24. Attribute VB_Exposed = False
  25. Option Explicit
  26. Private Sub Command1_Click()
  27. 'Always start ALL routines by declaring the variables you will be using!
  28.     Dim the_secret_number As Long
  29.     Dim counter As Long
  30.     Dim users_guess_string As String
  31.     Dim users_guess_number As Long
  32. 'First we'll randomize the timer so that we get a different
  33. 'random number every time we play.
  34.     Randomize Timer
  35. 'Next we'll generate our random number between 1 and 100
  36.     the_secret_number = Int((100 * Rnd) + 1)
  37. 'Now we'll set up a For-Next loop which will give the user 10 tries at
  38. 'guessing the secret number.
  39. For counter = 1 To 10
  40.     'Have the user take a guess.
  41.     users_guess_string = InputBox("Take a guess between 1 and 100")
  42.     'Let's convert the users guess from a string to a number.
  43.     users_guess_number = Val(users_guess_string)
  44.     'Let's compare his guess with the secret number.
  45.     If users_guess_number < the_secret_number Then
  46.         MsgBox (users_guess_number & " is too low")
  47.     End If
  48.     If users_guess_number > the_secret_number Then
  49.         MsgBox (users_guess_number & " is too high")
  50.     End If
  51.     If users_guess_number = the_secret_number Then
  52.         MsgBox (users_guess_number & " was the number! Congratulations!")
  53.         Exit Sub 'We have to exit the sub here, or we'll continue with the For-Next loop.
  54.     End If
  55. Next counter
  56. End Sub
  57.