Option Explicit On 
Option Strict On

Public Class frmGuess
    Inherits System.Windows.Forms.Form
    
#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Friend WithEvents lblGuess As System.Windows.Forms.Label
    Friend WithEvents lblLow As System.Windows.Forms.Label
    Friend WithEvents lblHigh As System.Windows.Forms.Label
    Friend WithEvents hsbGuess As System.Windows.Forms.HScrollBar
    Friend WithEvents btnCheck As System.Windows.Forms.Button

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.lblHigh = New System.Windows.Forms.Label()
    Me.lblGuess = New System.Windows.Forms.Label()
    Me.lblLow = New System.Windows.Forms.Label()
    Me.hsbGuess = New System.Windows.Forms.HScrollBar()
    Me.btnCheck = New System.Windows.Forms.Button()
    Me.SuspendLayout()
    '
    'lblHigh
    '
    Me.lblHigh.BackColor = System.Drawing.Color.White
    Me.lblHigh.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.lblHigh.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.lblHigh.ForeColor = System.Drawing.Color.Blue
    Me.lblHigh.Location = New System.Drawing.Point(288, 72)
    Me.lblHigh.Name = "lblHigh"
    Me.lblHigh.Size = New System.Drawing.Size(72, 32)
    Me.lblHigh.TabIndex = 0
    Me.lblHigh.Text = "100"
    Me.lblHigh.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'lblGuess
    '
    Me.lblGuess.BackColor = System.Drawing.Color.White
    Me.lblGuess.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.lblGuess.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.lblGuess.ForeColor = System.Drawing.Color.Red
    Me.lblGuess.Location = New System.Drawing.Point(144, 32)
    Me.lblGuess.Name = "lblGuess"
    Me.lblGuess.Size = New System.Drawing.Size(72, 32)
    Me.lblGuess.TabIndex = 0
    Me.lblGuess.Text = "50"
    Me.lblGuess.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'lblLow
    '
    Me.lblLow.BackColor = System.Drawing.Color.White
    Me.lblLow.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.lblLow.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.lblLow.ForeColor = System.Drawing.Color.Blue
    Me.lblLow.Location = New System.Drawing.Point(8, 72)
    Me.lblLow.Name = "lblLow"
    Me.lblLow.Size = New System.Drawing.Size(72, 32)
    Me.lblLow.TabIndex = 0
    Me.lblLow.Text = "1"
    Me.lblLow.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'hsbGuess
    '
    Me.hsbGuess.Enabled = False
    Me.hsbGuess.Location = New System.Drawing.Point(88, 80)
    Me.hsbGuess.Maximum = 109
    Me.hsbGuess.Minimum = 1
    Me.hsbGuess.Name = "hsbGuess"
    Me.hsbGuess.Size = New System.Drawing.Size(192, 24)
    Me.hsbGuess.TabIndex = 1
    Me.hsbGuess.Value = 1
    '
    'btnCheck
    '
    Me.btnCheck.Location = New System.Drawing.Point(136, 120)
    Me.btnCheck.Name = "btnCheck"
    Me.btnCheck.Size = New System.Drawing.Size(104, 24)
    Me.btnCheck.TabIndex = 2
    Me.btnCheck.Text = "&Pick Number"
    '
    'frmGuess
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(374, 179)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCheck, Me.hsbGuess, Me.lblHigh, Me.lblLow, Me.lblGuess})
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    Me.Name = "frmGuess"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Number Guess Problem"
    Me.ResumeLayout(False)

  End Sub

#End Region

  Dim TheNumber As Integer
  Dim MyGuess As Integer
  Dim MyRandom As New Random()



  Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
    If btnCheck.Text = "&Pick Number" Then
      'Get new number and set controls
      TheNumber = MyRandom.Next(100) + 1
      hsbGuess.Minimum = 1
      lblLow.Text = "1"
      hsbGuess.Maximum = 100 + hsbGuess.LargeChange - 1
      lblHigh.Text = "100"
      hsbGuess.Value = 50
      hsbGuess.Enabled = True
      btnCheck.Text = "&Check Guess"
    Else
      If MyGuess = TheNumber Then
        'Correct guess
        hsbGuess.Enabled = False
        lblLow.Text = ""
        lblHigh.Text = ""
        btnCheck.Text = "&Pick Number"
      ElseIf MyGuess < TheNumber Then
        'Guess is too low
        hsbGuess.Value = hsbGuess.Value + 1
        hsbGuess.Minimum = hsbGuess.Value
        lblLow.Text = Format(hsbGuess.Value, "0")
      Else
        'Guess is too high
        hsbGuess.Value = hsbGuess.Value - 1
        hsbGuess.Maximum = hsbGuess.Value + hsbGuess.LargeChange - 1
        lblHigh.Text = Format(hsbGuess.Value, "0")
      End If
    End If
    MyGuess = hsbGuess.Value
    lblGuess.Text = Format(MyGuess, "0")
  End Sub

  Private Sub hsbGuess_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles hsbGuess.Scroll
    'Read MyGuess and display it
    MyGuess = hsbGuess.Value
    lblGuess.Text = Format(MyGuess, "0")
  End Sub
End Class
