Option Explicit On 
Option Strict On

Public Class frmAdd
  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 lblNum1 As System.Windows.Forms.Label
  Friend WithEvents Label1 As System.Windows.Forms.Label
  Friend WithEvents lblNum2 As System.Windows.Forms.Label
  Friend WithEvents Label2 As System.Windows.Forms.Label
  Friend WithEvents Label3 As System.Windows.Forms.Label
  Friend WithEvents lblScore As System.Windows.Forms.Label
  Friend WithEvents lblMessage As System.Windows.Forms.Label
  Friend WithEvents btnNext As System.Windows.Forms.Button
  Friend WithEvents btnExit As System.Windows.Forms.Button
  Friend WithEvents txtAnswer As System.Windows.Forms.TextBox

  '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.txtAnswer = New System.Windows.Forms.TextBox()
    Me.Label1 = New System.Windows.Forms.Label()
    Me.Label2 = New System.Windows.Forms.Label()
    Me.Label3 = New System.Windows.Forms.Label()
    Me.lblScore = New System.Windows.Forms.Label()
    Me.lblMessage = New System.Windows.Forms.Label()
    Me.lblNum2 = New System.Windows.Forms.Label()
    Me.btnExit = New System.Windows.Forms.Button()
    Me.lblNum1 = New System.Windows.Forms.Label()
    Me.btnNext = New System.Windows.Forms.Button()
    Me.SuspendLayout()
    '
    'txtAnswer
    '
    Me.txtAnswer.Font = New System.Drawing.Font("Arial", 48!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.txtAnswer.Location = New System.Drawing.Point(336, 8)
    Me.txtAnswer.MaxLength = 2
    Me.txtAnswer.Name = "txtAnswer"
    Me.txtAnswer.TabIndex = 1
    Me.txtAnswer.Text = ""
    '
    'Label1
    '
    Me.Label1.Font = New System.Drawing.Font("Arial", 48!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label1.Location = New System.Drawing.Point(112, 16)
    Me.Label1.Name = "Label1"
    Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.Label1.Size = New System.Drawing.Size(64, 72)
    Me.Label1.TabIndex = 0
    Me.Label1.Text = "+"
    Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'Label2
    '
    Me.Label2.Font = New System.Drawing.Font("Arial", 48!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label2.Location = New System.Drawing.Point(272, 16)
    Me.Label2.Name = "Label2"
    Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.Label2.Size = New System.Drawing.Size(64, 72)
    Me.Label2.TabIndex = 0
    Me.Label2.Text = "="
    Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'Label3
    '
    Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 18!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label3.Location = New System.Drawing.Point(8, 104)
    Me.Label3.Name = "Label3"
    Me.Label3.TabIndex = 2
    Me.Label3.Text = "Score:"
    Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'lblScore
    '
    Me.lblScore.BackColor = System.Drawing.Color.Yellow
    Me.lblScore.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.lblScore.Font = New System.Drawing.Font("Times New Roman", 36!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.lblScore.Location = New System.Drawing.Point(8, 136)
    Me.lblScore.Name = "lblScore"
    Me.lblScore.Size = New System.Drawing.Size(104, 64)
    Me.lblScore.TabIndex = 3
    Me.lblScore.Text = "0"
    Me.lblScore.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'lblMessage
    '
    Me.lblMessage.BackColor = System.Drawing.Color.Cyan
    Me.lblMessage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
    Me.lblMessage.Font = New System.Drawing.Font("Microsoft Sans Serif", 24!, (System.Drawing.FontStyle.Bold Or System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.lblMessage.Location = New System.Drawing.Point(120, 96)
    Me.lblMessage.Name = "lblMessage"
    Me.lblMessage.Size = New System.Drawing.Size(320, 48)
    Me.lblMessage.TabIndex = 4
    Me.lblMessage.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'lblNum2
    '
    Me.lblNum2.Font = New System.Drawing.Font("Arial", 48!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.lblNum2.Location = New System.Drawing.Point(176, 16)
    Me.lblNum2.Name = "lblNum2"
    Me.lblNum2.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.lblNum2.Size = New System.Drawing.Size(100, 72)
    Me.lblNum2.TabIndex = 0
    Me.lblNum2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'btnExit
    '
    Me.btnExit.Location = New System.Drawing.Point(296, 160)
    Me.btnExit.Name = "btnExit"
    Me.btnExit.Size = New System.Drawing.Size(112, 23)
    Me.btnExit.TabIndex = 5
    Me.btnExit.Text = "E&xit"
    '
    'lblNum1
    '
    Me.lblNum1.Font = New System.Drawing.Font("Arial", 48!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.lblNum1.Location = New System.Drawing.Point(8, 16)
    Me.lblNum1.Name = "lblNum1"
    Me.lblNum1.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.lblNum1.Size = New System.Drawing.Size(100, 72)
    Me.lblNum1.TabIndex = 0
    Me.lblNum1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
    '
    'btnNext
    '
    Me.btnNext.Location = New System.Drawing.Point(160, 160)
    Me.btnNext.Name = "btnNext"
    Me.btnNext.Size = New System.Drawing.Size(112, 23)
    Me.btnNext.TabIndex = 5
    Me.btnNext.Text = "&Next Problem"
    '
    'frmAdd
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(460, 225)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnExit, Me.btnNext, Me.lblMessage, Me.lblScore, Me.Label3, Me.txtAnswer, Me.Label2, Me.lblNum2, Me.Label1, Me.lblNum1})
    Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
    Me.Name = "frmAdd"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Flash Card Addition"
    Me.ResumeLayout(False)

  End Sub

#End Region
  Dim Sum As Integer
  Dim NumProb As Integer, NumRight As Integer
  Dim MyRandom As New Random()

  Private Sub frmAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    NumProb = 0
    NumRight = 0
    btnNext.PerformClick()
  End Sub


  Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Close()
  End Sub

  Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
    'Generate next addition problem
    Dim Number1 As Integer
    Dim Number2 As Integer
    txtAnswer.Text = ""
    lblMessage.Text = ""
    NumProb = NumProb + 1
    'Generate random numbers for addends
    Number1 = MyRandom.Next(20)
    Number2 = MyRandom.Next(20)
    lblNum1.Text = Format(Number1, "#0")
    lblNum2.Text = Format(Number2, "#0")
    'Find sum
    Sum = Number1 + Number2
    btnNext.Enabled = False
    txtAnswer.Focus()
  End Sub



  Private Sub txtAnswer_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAnswer.KeyPress
    Dim Ans As Integer
    'Check for number only input and for return key
    Select Case e.KeyChar
      Case CChar("0") To CChar("9"), ControlChars.Back
        'number or backspace key is OK
        e.Handled = False
      Case ControlChars.Cr
        'Check answer
        Ans = CInt(txtAnswer.Text)
        If Ans = Sum Then
          NumRight = NumRight + 1
          lblMessage.Text = "That's correct!"
        Else
          lblMessage.Text = "Answer is " + Format(Sum, "#0")
        End If
        lblScore.Text = Format(100 * NumRight / NumProb, "##0")
        btnNext.Enabled = True
        btnNext.Focus()
        e.Handled = False
      Case Else
        e.Handled = True
    End Select
  End Sub
End Class
